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: Wrong Answer

Solution code:
import re

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

keypt = "#\."

matchnum = len(re.findall('%s'%keypt, s))

print(matchnum)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

N = int(input())
S = str(input())
Sarray = list(S)
Sarraynum = []

#白0
'''
for i in range(len(Sarray)):
    if Sarray[i] == '.':
        Sarraynum.append(0)
    else:
        Sarraynum.append(1)
'''
d = []
for i in range(len(Sarray)):
    if Sarray[i] == '.':
        d.append(i)
e = []
f = 0
g = 0
for i in range(1,len(d)):
    e.append(d[i] - d[i-1])
    if e[i - 1] >= f:
        f = e[i - 1]
        g = i

b = 0
for j in range(0,g):
    if Sarray[j] == '#':
        b += 1
for j in range(g+1,len(Sarray)):
    if Sarray[j] == '.':
        b += 1
print(b)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
t=-1
for i in range(n):
    if s[-1]=="#":
        s.pop(-1)
x=min(s.count("."),s.count("#"))
if x==0:
    x=1
print(x)

Submission status: Wrong Answer

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

listS = list(S)
count1 = 0
count2 = 0
count3 = 0
count4 = 0

a = 0
b = 0

for i in range(N):
    if listS[i] == '.':
        continue
    else:
        a = i
        break

for i in range(N):
    if listS[N-1-i] == '#':
        continue
    else:
        b = N-i
        break

count1 = listS[:N-1].count('#')
count2 = listS[1:].count('.')
count3 = listS[a:b].count('.')
count4 = listS[a:b].count('#')

print(min(count1, count2, count3, count4))

Submission status: Wrong Answer

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

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

r = len(S)
for i, s in enumerate(reversed(S)):
    if s == '.':
        r = len(S) - i
        break

count_b = 0
count_w = 0
for i, s in enumerate(S[l:r]):
    if s == '#':
        count_b += 1
    else:
        count_w += 1

ans = min(count_b, count_w)

print(ans)

Submission status: Wrong Answer

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

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

for i in range(N):
    if i<dot and S[i]!=".":
        count+=1
for i in range(N):
    if i<sha and s_r[i]!="#":
        count+=1
#print(count)

a=0
b=0

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

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

Submission status: Wrong Answer

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

l=[t,r]
x=[len(list(v))for k,v in groupby(s)if k=="#"]
y=[len(list(v))for k,v in groupby(s)if k=="."]
if len(x)>len(y):
    y=[0]+y
elif len(x)<len(y):
    x=[0]+x

x=array([0]+list(accumulate(x)))
y=array(list(accumulate(y[::-1]))[::-1]+[0])
print(min(x+y))

Submission status: Wrong Answer

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

MAX = 2 * (10 ** 5)

# . : white
# # : black
# no '#.' sequence

# a list that represents no of stone of the color interested up to that indices
nwhite, nblack = [], []

cur_nwhite, cur_nblack = 0, 0
for c in S:
    if c == '.':
        cur_nwhite += 1
    else:
        cur_nblack += 1

    nwhite.append(cur_nwhite)
    nblack.append(cur_nblack)

if cur_nwhite == 0 or cur_nblack == 0:
    print(0)

else:
    # indices of start of the sequence of black stones
    black = []
    flag = False

    for i, c in enumerate(S):
        if c == '#':
            if not flag:
                black.append(i)
                flag = True
        
        else:
            flag = False

    print('white: ',nwhite)
    print('black: ', nblack)
    print('i-black: ',black)

    ans = MAX + 1

    # set a index that starts sequence of black(#)
    for i in black:

        curans = 0

        # then turn over all black(#) left to it
        if i > 0:
            curans = nblack[i-1]

        # then turn over all white(.) right to it    
        curans += (cur_nwhite - nwhite[i])

        ans = min(ans, curans)

    print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import cumsum

N = int(input())
S = input()
ss = S.replace("#", "1").replace(".", "0")
* ls, = map(int, ss)
cum_ls = cumsum(ls)

ans = 10**10
for i in range(1, N-1):
    ans = min(ans, cum_ls[i] + (N-(i+1) - (cum_ls[-1] - cum_ls[i])))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
count = 1
for i in s:
  if i == ["#"]:
    if s[(s.index(i))+1] == ["."]:
      count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
cnt1 = 0
cnt2 = 0
initdot = True
for idx,s in enumerate(S):
    if s=="#" and idx < N-1:
        cnt1+=1
        initdot = False
    if s=="." and initdot:
        cnt2+=1
if cnt1 < cnt2:
    print(cnt1)
else:
    print(cnt2)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
for x in range(N):
    if x == 0:
        ans = S.count(".")
        continue
    count = S[:x].count("#") + S[x:].count(".")
    if count < ans:
        ans = count
    print(count)
count = S.count("#")
if count < ans:
    ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
first_B = S.find('#') #最初の黒より前の白を消去するため　初めて出てくる黒の場所を取得
if first_B == -1: #黒がない=全部白-->回数0
    answer = 0
else:
    S = S[first_B:] #最初の白の部分を全部消去
    rev_S = S[::-1] #反転　終わり側から続く黒は不要なため
#    print (rev_S, 'rev_S')
#    print(S)
    last_W = rev_S.find('.') #(反転後で)最初の白より前の黒を消去するため　反転後に初めて白が出てくる場所を取得　
    if last_W == -1: #白がない-->全部黒-->もともと白...白＋黒...黒 -->k耐えは0回
#        n_W = S.count('.')
#        n_B = S.count('#')
#        if n_W > n_B:
#            answer = n_B
#        else:
#           answer = n_W
        answer = 0
    else:
        S = rev_S[last_W:] #最初の黒の部分を全部消去
        S = S[::-1] #反転
#        print (S)
        n_W = S.count('.')
        n_B = S.count('#')
        if n_W > n_B:
            answer = n_B
        else:
            answer = n_W
print (answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
a = 0
b = 0
flag = 0
for i in range(len(s)):
    if flag == 0:
        if s[i] == '#':
            if i != 0:
                ans += min(a,b)
                if a < b and '.' in s[:i]:
                    flag = 1
                a = 0
                b = 0
            a += 1
        if s[i] == '.':
            b += 1
            if i == len(s) -1:
                ans += min(a,b)
    if flag == 1:
        ans += s[i+1:].count('.')
        break
print(ans)

Submission status: Wrong Answer

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

def count_renzoku(S,s):
    renzoku=1
    for i in range(1,len(S)):
        if S[i]==s:
            renzoku+=1
        else:
            break
    return renzoku

if S.count('#')==N or S.count('.')==N:
    print(0)
else:
    a=min(S.count('#'),S.count('.'))
    T=S[::-1]
    if T[0]=='#':
        T=T[count_renzoku(T,'#'):]
    S=T[::-1]
    if S[0]=='.':
        S=S[count_renzoku(S,'.'):]
    print(min(a,S.count('#'),S.count('.')))

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
#print(N,S)
count=0
num = 0

if not "#" in S or not "." in S:
  print(0)
else:
  #S_r = list(reversed(S))
  #print(S_r)
  for i in range(len(S)):
    #print(i, S[i])
    if S[i] == "#":
      num = i
      #print(num)
      break
    else:
      continue
  #print(num)
  print(S[num:].count("."))

Submission status: Wrong Answer

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

cnt = 0
cnt_black = 0
should_change = 0
to_fl = 0
for i in range(N):

    if S[i] == '#':
        cnt_black += 1
        to_fl += 1
    else:
        should_change += to_fl
        to_fl = 0


# print(N, cnt_black, N-cnt_black, should_change)

if should_change < (N - cnt_black):
    print(should_change)
else:
    print(N-cnt_black)

Submission status: Wrong Answer

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

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



x=array([0]+list(accumulate(x)))
y=array(list(accumulate(y[::-1]))[::-1]+[0])
print(min(x+y))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=0
b=0
if n%2!=0:
    for i in range(0,n-1,2):
        if s[i]!=s[i+1]:
            a=a+1
    if a>0 and s[n-1]!='#':
        print(a+1)
    else:
        print(a)
else:
    for i in range(0,n-1,2):
        if s[i]!=s[i+1]:
            a=a+1
    print(a)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

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

    return min(w_num, b_num)


print(main())

Submission status: Wrong Answer

Solution code:
print("0")

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black =False
w_num = 0
b_num =0
for i in range(N):
    if black:
        if S[i]==".":
            w_num +=1
    
    if S[i]=="#":
        black =True
        b_num +=1
r_black =0
for j in range(N):
    if S[N-j-1] == "#":
        r_black += 1
    elif S[N-j-1] == ".":
        break


ans = min([w_num,b_num-r_black,N-b_num])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
xx = []
ten = []
count = 0#最初
count1 = 0 
count2 = 1
count3 = 0
count4 = 0
count5 = 0
for i in S:
    if i=="#" and count==0:
        count1 += 1
        count = 1
       
    elif i =="#" and count2==1 and count==1:
        count1 += 1
        
    elif i =="." and count2==1 and count==1:
        xx.append(count1)
        count1 = 1
        count2 = 0
        
    elif i =="." and count2==0 and count==1:
        count1 += 1

    elif i=="#" and count2==0 and count==1:
        ten.append(count1)
        count1 = 1
        count2 = 1


if count2==0 and count1>=1:
    ten.append(count1)

for i in range(len(xx)):
    if (xx[i]+count5)>=ten[i]:
        count3 += ten[i]
        count5 += ten[i]+xx[i]
    else:
        count3 += xx[i]
        count5 = 0
count4 = sum(xx)
if count3 > count4:
    count3 = count4
        
print(count3)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
list = [0]*N

for i in range(N-1):
    if S[i:i+2] == '#.' and (S[:i-1].count('.') == len(S[:i-1]) or (S[:i-1].count('.')+list[:i-1].count(1) == len(S[:i-1]))):
        list[i] = 1
    elif S[i:i+2] == '#.':
        list[i+1] = 2

for i in range(N-1):
    if list[i] == 2 and S[i+1] == '.':
        list[i+1] = 2

print(list.count(1)+list.count(2))

Submission status: Wrong Answer

Solution code:
n=int(input())

s=input()


flg=0
shiro=0
kuro=0
bef="."
ans=0
for i in range(n):
  if bef=="#" and s[i]==".":
    flg=1
  
  if bef=="." and s[i]=="#" and flg==1:
    ans+=min(shiro,kuro)
    shiro=0
    kuro=0
    flg=0
  else:
    if s[i]=="#":
      kuro+=1
    else:
      shiro+=1
  bef=s[i]

if flg==1:
  ans+=min(shiro,kuro)


print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
sum = 0
for char in s:
    if char == '#':
       sum = sum +1 
if sum > eval(n)/2:
    sum = eval(n) - sum

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = list(input())
S2 = S1.copy()
count1 = 0
count2 = 0
for i in range(0, N-1, 1):
    if S1[i] == "#" and S1[i + 1] == ".":
        S1[i + 1] = "#"
        count1 += 1

for i in range(N-1, 0, -1):
    if S2[i-1] == "#" and S2[i] == ".":
        S2[i-1] = "."
        count2 += 1
print(min(count1, count2))

Submission status: Wrong Answer

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

all_black = 0
all_white = 0
half = 0

for i in S:
    if i == '.':
        all_black += 1

for i in S:
    if i == '#':
        all_white += 1
        
for i in range(N-1):
    half_count = 0
    for j in S[:i+1]:
        if j == '.':
            half_count += 1
    for j in S[i+1]:
        if j == '#':
            half_count += 1
    if half_count > half:
        half = half_count

if all_white < all_black and all_white < half:
    print(int(all_white))
elif all_black < all_white and all_black < half:
    print(int(all_black))
else:
    print(int(half))

Submission status: Wrong Answer

Solution code:
# N = int(input())
#
# S = str(input())
#
# cnt = 0
# for i in range(1, N):
#     if S[i-1] == '#' and S[i] == '.':
#         cnt += 1
#
# cnt_2 = 0
# for i in range(N-2, -1, -1):
#     if S[i+1] == '.' and S[i] == '#':
#         cnt_2 += 1
#
#
# print(int(min(cnt, cnt_2)))

N = int(input())

S = str(input())

cnt = 0
target = S[0]
for i in range(N):
    if target == '#' and S[i] == '.':
        cnt += 1
        target = '#'  # 黒に変える
        continue

    if S[i] == '#':
        target = '#'
    else:
        target = '.'

cnt_2 = 0
aim = S[-1]
for i in range(N-1, -1, -1):
    if aim == '.' and S[i] == '#':
        cnt_2 += 1
        aim = '.'
        continue

    if S[i] == '#':
        aim = '#'
    else:
        aim = '.'


print(int(min(cnt, cnt_2)))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = list('##.#')
b = list('##..')
c = list('.#.#')
d = list('.#..')
ans = 0
if N == 1:
    print(0)
elif N == 2:
    if S == '#.':
        print(1)
    else:
        print(0)
elif N == 3:
    if S.find('#.') != -1:
        print(1)
    else:
        print(0)
else:
    S = '.' + S
    S = S + '#'
    t = list(S[:4])
    e = 3
    N += 2
    while True:
        if t == a or t == c:
            ans += 1
            t[2] = '#'
        elif t == b:
            ans += 2
            t[1] = '.'
        elif t == d:
            ans += 1
            t[1] = '.'
        e += 1
        if e > N-1:
            break
        t = t[1:] + [S[e]]
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
sl=[x for x in S]
sh=0
p=0
for i in range(N-1):
    if sl[i]=='#':
        sh+=1
    if sl[-i-1]=='.':
        p+=1

cnt=N-p-sh
print(p)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min_cost = n
left_cost = 0
right_cost = s.count('.')

for i in range(n):
    if s[i] == '#':
        left_cost += 1
    else:
        right_cost -= 1
    cost = left_cost + right_cost
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
sl = list(s)
if n > 2:
  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
      elif sl[i+2]=="." and sl[i-1]=="#":
        sl[i+1]='#'
        sl[i+2]='#'
        c = c + 2
      elif sl[i+2]=="#" and sl[i-1]=="#":
        sl[i+1]='#'
        c = c + 1
      elif sl[i+2]=="#" and sl[i-1]==".":
        sl[i]='#'
        c = c + 1
      elif sl[i+2]=="#":
        sl[i+1]='#'
        c = c + 1
  if sl[n-2]=="#" and sl[n-1]==".":
    sl[i+1]='#'
    c=c+1
elif n == 2:
  if s=="#.":
    c=c+1
else:
  pass
print(c)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
flag_b=0
sum_b=0
sum_w=0
for i in S:
    if i=="." and flag_b==1:
        sum_w+=1
        continue
    if i=="#" and flag_b==1:
        sum_b+=1
        continue
    if i=="#" and flag_b==0:
        flag_b=1
if sum_w >= sum_b:
    print(sum_b)
else:
    print(sum_w)

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
stemp=input()
s=[ i for i in stemp]
s.append("NG")

ans=0
f=0
f2=0
if s[0]=="#":
    f2=1
for i in range(n):
    if f2 and s[i]==".":
        ans+=1
    else:
        if f:
            if s[i]==".":
                ans+=1
        elif s[i]=="." and s[i+1]=="#":
                f=1
    #print(s[i], i, f, f2,ans)

print(ans)

Submission status: Wrong Answer

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

trial_num = int(input())
stones = list(input())

min_turn_stones = 2 * 10 ** 5

for i in range(trial_num):
    if(stones[i] == "."):
        tmp_min = stones[:i].count("#") + stones[i+1:].count(".")
        if (tmp_min < min_turn_stones):
            min_turn_stones = tmp_min

print(min_turn_stones)

Submission status: Wrong Answer

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

index = S.find("#")

if index == -1:
    print("0")
elif index == N-1:
    print("0")
else:
    print(S[index:].count("."))

Submission status: Wrong Answer

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

black_index = [j for j in range(len(s)) if s[j] =="#"]
white_index = [j for j in range(len(s)) if s[j] =="."]

if len(black_index) == 0 or len(white_index) ==0:
    print(0)
else:
    black_new_index = [black_index[j] for j in range(len(black_index)) if black_index[j]+1 not in black_index]
    white_new_index = [white_index[j] for j in range(len(white_index)) if white_index[j]+1 not in white_index]
    print(min(max(len(black_new_index),1), max(len(white_new_index),1)))

Submission status: Wrong Answer

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

flg = 0
idx = 0
for i in S:
    if i == '#' and flg == 0:
        flg = 1
        break
    idx += 1

if flg == 1:
    a = S[idx+1:].count('.')
    b = S[idx:].count('#')
    if S[-1] == '#':
        for ct in range(1, N+1):
            if S[-ct] == '.':
                break
        b -= ct-1
    ans = min(a, b)
else:
    ans = 0
key = [0]
S = S[idx:]
for i in range(1, len(S)):
    if S[i] == '#' and S[i-1] == '.':
        key.append(i)
if len(key) > 2:
    for i in range(len(key)-1):
        if S[:key[i+1]].count('#') >= ans or S[key[i+1]:].count('.') >= ans:
            break
        c = S[:key[i+1]].count('#') + S[key[i+1]:].count('.')
        ans = min(ans, c)

print(ans)

Submission status: Wrong Answer

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

left = stones.find("#")

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
num_w = 0
num_b = 0
exist_black = False
black = False
for i in range(N):
    if S[i] == '#':
        exist_black = True
        black = True
        if i != N-1 and S[i+1] == '.' and exist_black == True:
            num_b += 1

    elif S[i] == '.':
        black = False
        if exist_black == True:
            num_w += 1

if num_b <= num_w:
    print(num_b)
else:
    print(num_w)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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

def inverse(b, w, index, first):
    count = 0
    if first == '#':
        count = b[index//2 + 1] + w[-1] - w[(index + 1)//2]
    else:
        count = b[(index+1)//2] + w[-1] - w[index//2 + 1]
    return count

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

b = [0]
w = [0]
offset = 0
bsum = 0
wsum = 0
if first == '*':
    offset = 1
for i in range(len(num)):
    if i % 2 == offset:
        bsum += num[i]
        b.append(bsum)

offset = abs(offset -1)
for i in range(len(num)):
    if i % 2 == offset:
        wsum += num[i]
        w.append(wsum)
w.append(w[-1])
if len(num) == 1:
    print(0)
else:
    minlist = []
    minlist.append(sum(num[::2]))
    minlist.append(sum(num[1::2]))
    for i in range(len(num)):
        minlist.append(inverse(b, w, i, first))
    print(min(minlist))

Submission status: Wrong Answer

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

a = len(re.findall('#+.', S))
print(min(a,N-a))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
countB=0
flg=False

for i in range(N):
    if flg == False:
      if S[i] == '#':
          flg = True
          P = i
      else:
        continue

    if S[P] == S[i] :
        countB += 1
        continue
    else:
        count +=1

if count <= (N / 2):
    print(count)
else:
    if count > countB:
        print(countB)
    else:
        print(count)

Submission status: Wrong Answer

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

flag = False
countA = 0
countBtmp = 0
countB = 0
for i in range(N):
  if S[i] == '#':
    flag = True
    countBtmp = countBtmp + 1
  elif flag is True:
    countA = countA + 1
    countB = countBtmp

if countA < countB:
  print(countA)
else:
  print(countB)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += "-"
white = [0]
black = [0]
white_acc = 0
black_acc = 0
counter = 0
for i in range(n + 1):
    if s[i] == s[i - 1]:
        pass

    elif s[i - 1] == "#":
        black_acc += counter
        black += [black_acc]
        counter = 0
    elif s[i - 1] == ".":
        white_acc += counter
        white += [white_acc]
        counter = 0
    counter += 1
if len(black) + len(white) <= 3:
    exit()

last_white = white[len(white) - 1]
min_acc = 2 * 10 ** 5
if s[0] == "#":
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i])

else:
    black += [0]
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i - 1])
print(min(min_acc, last_white))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
ans_list=[]
for i in range(N):
    for j in range(N):
        if i > j :
            if S[j] =="#":
                ans +=1
        else:
            if S[j] ==".":
                ans +=1
    ans_list.append(ans)
    ans =0
ans_list.sort()
print(ans_list[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
bunki = N
countb = 0
l = N-1
for i in range(0, N):
	if(S[i] == '#'):
		bunki = i
		break
if(bunki != N):
	for j in range(bunki, N):
		if(S[j] == '.'):
			count += 1
		else:
			countb += 1 
	while(0 < l):
		if(S[l] == '#'):
			countb -= 1
		else:
			break
		l -= 1
if(countb < count):
	print(countb)
else:
	print(count)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
sum = 0
for char in s:
    if char == '#':
       sum = sum +1 
if sum > eval(n)/2:
    sum = eval(n) - sum
sum = str(sum)
print(sum)

Submission status: Wrong Answer

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

sharp_num = s.count('#')
dot_num = s.count('.')
print(min(sharp_num,dot_num))

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
tmp=N
for i in range(N+1) :
  k=s[:i].count("#")+s[i:N].count(".")
  if tmp>k:
    tmp=k
print(tmp+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

middle = S[1:-1]
white = middle.count('.')
black = middle.count('#')

if (S.count('.') == 0 or S.count('#') == 0) or (S.count('.') == 1 and S[0] == '.') or (S.count('#') == 1 and S[-1] == '#' ):
  print('0')
else:
  if white < black:
    if S[-1] == '.':
      print(white+1)
    else:
      print(white)
  else:
    if S[0] == '#':
      print(black+1)
    else:
      print(black)

Submission status: Wrong Answer

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
b = 0
w = 0
if len(encoded) <= 2:
    ans = 0
else:
    for i in range(len(encoded)):
        if i == 0:
            pass
        else:
            if i%2==1:#b
                b = b+encoded[i]
            else:
                w = w + encoded[i]
    if len(encoded)%2 == 0:
        b = b - encoded[-1]
print(min(b,w))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
n=len(s)
x = 0
for i in range(n-1):
    if s[i] == "#" and s[i + 1] == ".":
        y=0
        for j in reversed(range(i + 1)):
            if s[j] == "#":
                y += 1
            else:
                break

        x+=min(y, max(0,n-1-i))

print(str(x))

Submission status: Wrong Answer

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

s = list(s)

count1 = 0
count2 = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
count_sharp = s.count("#")
count_dot = s.count(".")
if count_dot == n or count_sharp == n:
    print(0)
else:    
    print(min(count_dot, count_sharp))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
c=0
b=S.count('#')
for i in range(1,N):
  if S[0]=='#'and S[1]== '.':
    S[0]='.'
    c+=1
  elif S[i-1]=='#'and S[i]=='.':
    S[i]='#'
    c+=1

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	S = input()
	S = S[:-1]

	ans = 0
	counts = 0
	flg = False
	for i in S:
		if i == "#":
			flg = True
		if flg == True and i == ".":
			ans += 1
		if i == "#":
			counts += 1
		
	bksp = S.split(".")
	bksp2 = bksp[-1]
	counts -= len(bksp2)


	print(min(ans, counts))

	

	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
if s.count(".") > s.count("#"):
    print(s.count("#"))
elif s.count("#") > s.count("."):
    print(s.count("."))
else:
    print(min(s.count("#"),s.count(".")))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input()) 
s = list(input().split('.'))

num = [i.count('#') for i in s[1:-1]]
m = sum(num)

print(m)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
S = input().strip()
S = S.rstrip("#")
print(min(S.count("#"), S.count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li = []
i = 0
j = 0
cnt = 0
ans = 0
while i<n:
    while j<n and s[i]==s[j]:
        cnt += 1
        j += 1
    i = j
    li.append(cnt)
    cnt = 0

if s[0] == "#" and len(li)!=1:
    if len(li)%2==0:
        a = sum(li[0::2])
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[-1]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
elif s[0] == "." and len(li)!=1:
    if len(li)%2==0:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
else:
    ans = 0

print(str(ans))