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:
N = int(input())
S = list(input())

if N == 1:
    print(0)
    exit()
if N == 2:
    if S[0] == "#" and S[1] == ".":
        print(1)
    else:
        print(0)
    exit()

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

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8
N = int(input())
S = list(input())
S1, S2 = S[:], S[:]
c1, c2 = 0, 0
for i in range(N-1):
    if S1[i] == "#" and S1[i+1] == ".":
        c1 += 1
        S1[i+1] = "#"
    if S2[i] == "#" and S2[i+1] == ".":
        c2 += 1
        S2[i] = "."
print(min(c1, c2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
s += [0]
import collections as coll
t = coll.Counter(s)
b1,w1=t["#"],t["."]

b = 0
w = 0
p = 0
q = 10 ** 18
for i in range(n):
    if s[i] == "#":
        b += 1
    else:
        w += 1
    p = b + w1 - w
    if p < q:
        q = p

print(q)

Submission status: Wrong Answer

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

count = 0
for idx in range(len(S) - 1):
    if S[idx] == '#':
        if S[idx + 1] == '.':
            count += 1

print(count)

Submission status: Wrong Answer

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

ans = 0
for i in range(N-1):
    if i != 0 and i != N-2:
        tmp1 = S[i-1]
        tmp2 = S[i]
        tmp3 = S[i+1]
        tmp4 = S[i+2]
        if tmp2 == '#' and tmp3 == '.':
            if tmp1 == '#':
                S[i+1] = '#'
                ans += 1
            elif tmp4 == '.':
                S[i] = '.'
                ans += 1
            else:
                S[i+1] = '#'
                ans += 1
    if i == 0:
        tmp2 = S[i]
        tmp3 = S[i+1]
        if tmp2 == '#' and tmp3 == '.':
            S[i] = '.'
            ans += 1
    if i == N-2:
        tmp2 = S[i]
        tmp3 = S[i+1]
        if tmp2 == '#' and tmp3 == '.':
            S[i+1] = '#'
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
l=list(input())
m=0
lm=[]
for i in range(n):
    if (l[i]=="#"):
        lm=l[m:]
        break
print(lm.count("."))

Submission status: Wrong Answer

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] == "#"]

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

Submission status: Wrong Answer

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

out_num_list=[]

change_num=0
for i in range(0,N-1):
  if S[i] == '#':
    change_num+=1
    
out_num_list.append(change_num)

change_num=0
for i in range(1,N):
  if S[i] == '.':
    change_num+=1
    
out_num_list.append(change_num)

print(min(out_num_list))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black = S.count('#')
white = S.count('.')
count = 0
S.append(0)
if black > white:
    for i in range(0,N):
        if S[i]=='#' and S[i+1]=='.':
            S[i+1]='#'
            count += 1
else:
    for i in range(0,N):
        if S[i]=='#' and S[i+1]=='.':
            S[i+1]='.'
            count += 1
print(count)

Submission status: Wrong Answer

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

if n == 1:
    print(0)
else:
    siro = s.count(".")
    if s[0] == ".":
        siro -=1
    
    kuro = n-siro
    if s[-1] == "#":
        kuro -=1

    mini = min(siro,kuro)

    
    print(mini)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = S[S.find('#'):]
a = S.count('#')
b = S.count('.')
print(min(a, b))

Submission status: Wrong Answer

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

ans = 0
now = S[0]
for i in range(N):
    if S[i] != now:
        ans += 1
        now = '*' if now == '.' else '.'
if ans > 1:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

s = list(S)

change = False
i = 0
count = 0
for c in s:
    if c == '#':
        change = True
    elif change == True:
        count += 1
        change = False
    i += 1

change = False
i = 0
r_count = 0
for c in (reversed(s)):
    if c == '.':
        change = True
    elif change == True:
        r_count += 1
        change = False
    i += 1

if r_count < count:
    print(r_count)
else:
    print(count)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i] == '#':
        first_black = i+1
        break
    first_black = i+1

cnt = 0
if first_black == N:
    pass
else:
    for i in range(first_black-1,N,1):
        if S[i] == '.':
            cnt += 1

if S[N-1] == '#':
    white = N-first_black-cnt
else:
    white = N-first_black-cnt+1
    
if white > cnt:
    print(cnt)
else:
    print(white)

Submission status: Wrong Answer

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

flag = 0
count = 0
for i in range(N):
    if S[i] == '#':
        flag = 1
    elif flag == 1:
            count = count + 1

print(count)

Submission status: Wrong Answer

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

num_W = 0  
for i in S:
    if i == ".":
        num_W += 1
num_B = N - num_W

if num_W < num_B:
    print(num_W)
else:
    if S[N-1] == "#":
        last_B = 0
        for j in S[::-1]:
            if j == "#":
                last_B += 1
            else:
                break
        print(num_B - last_B)
    else:
        print(num_B)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li = []
for i in range(n):
    if s[i] == "#":
        li.append(i)
li.append(len(s))
sum = 0
if len(li) == 1:
    print(0)
else:
    for i in range(len(li)-1):
        sum += li[i+1]-li[i] - 1
    print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
t = s.replace(".","0").replace("#","1")
count1=0
count2=0
 
for i in range(len(t)):
	if int(t[i]) == i%2:
		count1 += 1
	else:
		count2 += 1
print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input() + '#'

flag = 0
b = 0
w = 0
ans = 0
for i in range(N + 1):
    if S[i] == '#':
        if flag == 2:
            ans += min(b, w)
            b = 1
            w = 0
            flag = 1
        else:
            b += 1
            flag = 1
    else:
        if flag == 1:
            w += 1
            flag = 2
        elif flag == 2:
            w += 1
        
print(ans)

Submission status: Wrong Answer

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

array = [0]

before = S[0]
add = 0

for s in S:
	if before == s:
		array[-1] = array[-1] + 1
	else:
		array.append(1)
	before = s

if S[0] == '.':
	array.pop(0)

result = 0
for i in range(len(array)):
	if i % 2:
		continue
	if i + 1 >= len(array):
		result += array[i]
	else:
		result += min(array[i],array[i+1])

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
f,ans,b,w = 0,0,0,0
for i in s:
  if i == '#':
    if f == 0:
      ans+= min(b,w)
      b,w = 0,0
    b+=1
    f = 1
  else:
    w +=1
    f = 0
ans += min(b,w)
print(ans)

Submission status: Wrong Answer

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

a=0
b=0

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

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

Submission status: Wrong Answer

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

change = 0
br = 0
wh = 0
for i in range(a):
  if(b[i] == '#'):
    change = 1
  if change == 1:
    if(b[i] == '#'):
      br += 1
    else:
      wh += 1
if(br >= wh):
  print(wh)
else:
  print(br)

Submission status: Wrong Answer

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

res1 = 0
for i in range(N-1):
    if S[i] == '#' and S[i+1] == '.':
        res1 += 1
        S[i+1] = '#'
        
res3 = 0
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, res3))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
h=0
b=0
for i in range(len(s)):
    if s[i]=="#":
        b+=1
    if s[i]=="." and b!=0:
        h+=1
b2=0
h2=0
for i in range(len(s)-1,-1,-1):
    if s[i]=="#" and h2!=0:
        b2+=1
    if s[i]==".":
        h2+=1

print(min(h,b2))

Submission status: Wrong Answer

Solution code:
import sys

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

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

if len(S) == 1:
    print(0)
    sys.exit()

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

Solution code:
n = int(input())
s = input()
x = sum(1 if s[i] != "#" else 0 for i in range(n))
y = sum(0 if s[i] != "#" else 1 for i in range(n))
print(min(x, y))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
for i in range(n):
    s.append("#")
count = 0
for i in range(n):
    if s[i] == "#" and s[i+1] == ".":
        init = i+1
        break
for i in range(n):
    # #=kuro .=shiro

    if s[i] == "#" and s[i+1] == ".":
        c = 1
        for j in range(n):
            if s[i+j+2] == ".":
                c += 1
            else:
                break
        if count == 0 and init < c:
            c = init
        count += c
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
k = 0
ans0 = 0
ans1 = 0

for i in range(N):
    if S[i] == "#":
        k = i
        break

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

for i in range(N):
    if S[i] == "#":
        ans1 +=1



print(min(ans0,ans1))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

b = sum([1 for i in s if i=="#"])
w = n-b

ans = 0
f = False

for i in s:
    if i == "#":
        b-=1
        if b<w and not f:
            ans+=1
        else:
            f = True
    else:
        if f:
            ans+=1
        w-=1


print(ans)

Submission status: Wrong Answer

Solution code:
"""
python3 a.py < input.txt
"""
import math
import itertools as it
import heapq

N=int(input())
S=input()
lb=None
for i in range(N):
    if S[N-i-1] == "#":
        lb=N-i-1
if lb==None:
    print(0)
    exit(0)
rw=None
for i in range(N):
    if S[i]==".":
        rw=i
if rw==None:
    print(0)
    exit(0)
nw=0
nb=0
for i in range(lb, rw-1):
    if S[i] == "#":
        nb = nb+1
    if S[i] == ".":
        nw = nw+1

if lb != None:
    print(min(nb, nw))
else:
    print(0)

Submission status: Wrong Answer

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-cld,cah-clh))

    last_s = s

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
first = N
idx = 0
ans = 0
for i in S:
  if i == '#':
    first = idx
    break
  idx += 1
for i in S[first:]:
  if i == '.':
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    N = int(input())
    S = input()
    for i in range(N-1):
        if S[i:i+2]=='#.':
            if i==0 or ((i-1)>=0 and S[i-1]=='.'):
                S = S[:i] + '.' + S[i+1:]
            else:
                S = S[:i+1] + '#' + S[i+2:]
    print(S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

haichi = a[1]
prev_haichi = '.'
count = 0
for each_haichi in haichi:
    if prev_haichi == '#' and each_haichi == '.':
        count += 1
        prev_haichi = '#'
    else:
        prev_haichi = each_haichi
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
try:
  leftb = s.index('#')
except:
  leftb = -1

if leftb >= 0:
  w = s[leftb:].count('.')
  b = s[leftb:].count('#')
  if s[-1] == '#':
    b -= 1
  ans = min(w,b)
else:
  ans = 0
print(ans)

Submission status: Wrong Answer

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

s = list(S)
s3 = s.count("#")
s4 = s.count(".")
for i in range(N-1, -1, -1):
    if s[i] == "#":
        s[i] = ""
    else:
        break
    
for i in range(N):
    if s[i] == ".":
        s[i] = ""
    else:
        break

s1 = s.count(".")
s2 = s.count("#")

print(min(s1, s2, s3, s4))

Submission status: Wrong Answer

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

i = S.find('#')
if i < 0:
    print(0)
else:
    print(S[i:n].count('.'))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
siro = s.count(".")
ren = 0
i = 1
while i <= n :
    if s[-i] == "#" :
        ren += 1
        i += 1
    else :
        break
ku = 0
if n-siro >= 1:
    ku = s.index("#")
print(min(siro,n-ren-siro,s[ku:].count(".")))

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnta = s.count("#")
cntb = s.count(".")
ans = min(cnta,cntb)
for i in range(N):
	if s[i] == "#":
		tmp = i
		ans = min(ans,N-(cnta+i))
		break

cnt = 0
f = 0
for i in range(N-1,-1,-1):
	if f == 0:
		if s[i] == ".":
			f = 1
	else:
		if s[i] == "#":
			cnt += 1
else:
	ans = min(ans,cnt)
	
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
N = int(input())
S = input()

min = N
if S.count('#') == N or S.count('.') == N:
    print(0)
else:
    l = 0
    r = S.count('.')
    for n in range(1,N+1):
        if S[n-1] == '#':
            l += 1
        else:
            r -= 1
        if l+r < min:
            min = l+r
        print(min)
    print(min)

Submission status: Wrong Answer

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

a=S.count('#.')
print(a)

Submission status: Wrong Answer

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

W = '.'
B = '#'

first_B = S.find(B)

print(min(S[first_B:].count(W), S[first_B:].count(B)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(raw_input())
S = str(raw_input())
all_sharp = S.count('.')
 
for i in range(N):
	if S[N-i-1] == '.':
		num = i
		all_dot = S[:N-num].count('#')
		print min(all_sharp, all_dot)
		sys.exit()
print 0

Submission status: Wrong Answer

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

for i, c in enumerate(s):
    if c == "#":
        s = s[i:]
        break

count_hash = s.count("#")
count_period = s.count(".")

if count_hash >= count_period:
    print(count_period)
else:
    print(count_hash)

Submission status: Wrong Answer

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

S_list = list(S)
firstBlack = N
countStone = 0
for i in range(0, N):
  if(S_list[i] == "#"):
    firstBlack = i
    break

countStone = S_list[firstBlack:N].count(".")
    
print(countStone)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
st=input()
flag=False
count=0
for i in range(n):
	if st[i]=='#' and not flag:
		flag=True
	if flag and st[i]=='.':
		count+=1
count1=0
flag=False
for i in range(n):
	if st[n-i-1]=='.' and not flag:
		flag=True
	if flag and st[n-i-1]=='#':
		count1+=1
count2=st.count('#')
print(min([count,count1,count2]))

Submission status: Wrong Answer

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


from sys import stdin


############################################


# read data for n sequences.
n = stdin.readline()
N = int(n)
n = stdin.readline()
S = str(n)

#data = [int(stdin.readline().rstrip()) for _ in range(n)]

out=[]
count=0
for i,l in enumerate(S):
	if i < N:	
		if l != "#":
			count+=1

count2=N-count
print(min([count,count2]))

Submission status: Wrong Answer

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

start = s.find('.')
if start == -1 or start == n - 1:
    print(0)
    exit()
ast  = s.count('.', start)
hash = s.count('#', start)

print(min(ast, hash))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop


def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))


def runLength(in_str):
    kukan = 1
    start = 0
    ret = []
    for i in range(1,len(in_str)):
        if in_str[i-1]!=in_str[i]:
            ret.append([in_str[i-1],kukan,start])
            start = i
            kukan=0
        kukan+=1
    ret.append([in_str[-1],kukan,start])
    return ret

N = int_raw()
S= input()

dp = {}

def rec(ss):
    return 0

def main():
    ans =0
    numB = 0
    leftMostW = -1
    for i in range(len(S)-1,-1,-1):
        if S[i]==".":
            leftMostW = i
            break
    if leftMostW ==-1:
        return 0
    for i in range(leftMostW+1):
        if S[i] == "#":
            numB+=1
    return min(numB,leftMostW+1-numB)



print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
flg = 0
cnt = 0
for i in range(N):
    if S[i] == '#':
        flg = i
        break

for j in range(N - flg):
    if S[flg + j] == '.':
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

ans1,ans2,ans3,ans4 = 0,0,0,0
for i in range(N):
  if(i != 0):
    if((S[i-1] == '#')and(S[i] == '.')):
      ans1 += 1
      S[i] = '#'
    if((U[i-1] == '.')and(U[i] == '#')):
      ans4 += 1
      U[i] = '.'
  if(T[i] == '#'):ans2 += 1
  if(T[i] == '.'):ans3 += 1
    
ans = min(ans1,ans2,ans3,ans4)
print(ans)

Submission status: Wrong Answer

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

ans = 0

for i in range(1,n):
    if s[i-1] != s[i] and s[i-1]!= '0':
        s[i] = '0' 
        ans += 1



print(ans)

Submission status: Wrong Answer

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

allw = 0
allb = 0
tmpb = 0
ss = True if s[0] == '.' else False
for _s in s:
  if not ss and _s == '.':
    allb += 1
    if tmpb > 0:
      allw += tmpb
      tmpb = 0
  elif _s == '#':
    tmpb += 1
    ss = False
print(min(allw, allb))

Submission status: Wrong Answer

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

w_counter_all = 0
for i in range(n):
    if s[i] == '.': # white
        w_counter_all += 1

if s[0] == '.':
    cost1 = 0
else:
    cost1 = 1
cost1_list = [cost1]
for i in range(1, n):
    if s[i] == '#':
        # black
        cost1 += 1
    cost1_list.append(cost1)



if w_counter_all == 0:
    print(0)
else:
    cost_all = []
    for i in range(n):
        cost_all.append(n - i - 1 - cost1_list[-1] + cost1_list[i] * 2)
    print(min(cost_all))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S == '.' * N:
  print(0)
else:
  first = 0
  for i in range(1,N+1):
    if S[i-1] == '#':
      first = i
      break
  out1 = 0
  for i in range(first+1,N+1):
    if S[i-1] =='.':
      out1 += 1
  second = 0
  for i in range(1,N+1):
    if S[i-1] == '.':
      second = i
      break
  out2 = 0
  for i in range(first+1,N+1):
    if S[i-1] =='#':
      out2 += 1
  print(min(out1,out2))

Submission status: Wrong Answer

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")


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

if (S.count('.')==N) or (S.count('#')==N):
	print(0)
	exit()


#	s = "abc345abc"
#	print(s.find("a"))		#=> 0

i = S.find('#.')
a = S[(i+1):]
b = S[:(i+1)]

p(i, a)
p(i, b)

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


#		l = sorted(s, reverse=True)
#		print(l)						#=> ['y', 't', 'o', 'n', 'h', 'P']
#		print( "".join(l) )				#=> ytonhP

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
index = 0
index2 = 0

for i in range(N):
    if S.count("#") == 0:
        print(ans)
        exit()
    if S[N - 1 - i] == "#":
        print(i)
        index = N - 1 - i
        break

ans += N - index - 1

for j in range(index):
    if S[index - 1 - j] == ".":
        index2 = index - 1 - j


for k in range(index2):
    if S[k] == "#":
        ans += 1

print(ans)

Submission status: Wrong Answer

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

for i, s in enumerate(S):
    if s == '#':
        n = S[i:].count('.')
        break
    else:
        n = 0
for i, s in enumerate(reversed(S)):
    if s == '.':
        m = S[i:].count('#')
        break
    else:
        m = 0
print(min(n, m))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = int(input());
s=list(input());
 
j = 0;
k = 0;
 
for i in range(len(s)):
    if str(s[i]) == '#':
          j = j + 1;
    else:
        k = k + 1;
 
print(min(k,j));

Submission status: Wrong Answer

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

cnt_w = 0
flg = 0
for i in range(N-1):
    if flg and S[i+1] == '.':
        cnt_w += 1
    elif S[i] == '#' and S[i+1] == '.':
        flg = 1
        cnt_w += 1
    else:
        flg = 0

cnt_b = 0
flg = 0
for i in range(N-1, 0, -1):
    if flg and S[i-1] == '#':
        cnt_b += 1
    elif S[i-1] == '#' and S[i] == '.':
        flg = 1
        cnt_b += 1
    else:
        flg = 0

print(min(cnt_w, cnt_b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ansW = 0
ansB = 0

def indB(str) :
	for i in range(n) :
		if str[i] == "#" : 
			return i
	return -1

indexB = indB(s)
if indexB != -1 :
	for i in range(indexB, n) :
		if s[i] == "." : 
			ansW += 1
            
def indW(str) :
	for i in range(n-1,0,-1) :
		if str[i] == "." : 
			return i
	return -1

indexW = indW(s)
if indexW != -1 :
	for i in range(indexW-1,0,-1) :
		if s[i] == "#" : 
			ansB += 1

print (min(ansW,ansB))

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 and c != "#":
            continue
        if c == "#":
            is_start = True
            b_num += 1
            continue
        if is_start and c == ".":
            w_num += 1
        if is_start and c == "#":
            b_num += 1

    return min(w_num, b_num)


print(main())

Submission status: Wrong Answer

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

flag = False
count_w = 0
count_b = 0
for i in list(S):
    if(i == '#'):
       count_b += 1
       if(flag != True):
           flag = True
    else:
        if(flag):
            count_w += 1
count_ex = 0
for i in list(S[::-1]):
    if(i == '#'):
       count_ex += 1
    else:
        break
print(min(count_w, count_b - count_ex))

Submission status: Wrong Answer

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

X = [0 if x == '#' else 1 for x in S] # 0:black 1:white
Y = list(reversed(X))

if 0 not in X or 1 not in X:
    ans = 0 
else:
    idx = X.index(0) # first black
    X = sum(X[idx:])
    Y = N - idx - X - Y.index(0)
    ans = min(X, Y)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = 0
cnt1 = 0
cnt2 = 0

for i in range(n):
    if s[n-i-1] == '#':
        a += 1
    else:
        break
        
s = s[0:n-a]

for i in range(n-a):
    if s[i] == '#':
        cnt1 += 1
    else:
        cnt2 += 1
        
print(min(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = input()
pt = S.find("#")
ct = 0
bl_ls = []
wh_ls = []
last_wh = 0
last_bl = 0
if pt == -1:
    print(0)
else:
    for i in range(N):
        if S[i] == ".":
            last_wh += 1
            wh_ls.append(last_wh)
            bl_ls.append(last_bl)
        else:
            last_bl += 1
            wh_ls.append(last_wh)
            bl_ls.append(last_bl)
    _min = 1e9
    for i in range(N):
        res = wh_ls[N-1] - wh_ls[max(0,i-1)] + bl_ls[max(0,i-1)]
        _min = res if res < _min else _min
    print(_min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def counting(seq, s):
  return seq.count(s)

idx_list = []
for i in range(N-1):
  if S[i] != S[i+1]:
    idx_list.append(i)

count_list = []
for i in idx_list:
  count_list.append(counting(S[:i], "#") + counting(S[i:], "."))
count_list.append(counting(S, "#")+0)
print(min(count_list))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
p=0
count=0
ketu=0
#左から黒をカウントして、黒を返すだけで済むならそっちを採用する、
#そうでないなら特定の黒より右で、少ない方に応じて色を変える
#黒がシャープ白がドット
for i in range(N):
    if S[i]=='#':
        count=S[i:].count('#')
        p=i
        break
    else:
        pass
S_reverse=S[::-1]
for i in range(N):
    if S_reverse[i]=='#':
        ketu=ketu+1
    else:
        break
print(min(count-ketu,N-p-count))
#この後にケツからシャープ数えて引ける可能性もある

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
nb = s.count('#')
nw = s.count('.')
if nw == n or nb == n:
    print(0)
    exit()
lb = 0
rw = nw

b = False
ans = float('inf')
for i in range(n):
    if b == False and s[i] == '#':
        ans = min(ans, lb + rw)
        b = True
        lb += 1
    elif s[i] == '#':
        lb += 1
    elif s[i] == '.':
        rw -= 1
        b = False
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
t = S.count(".")
if t == N:
    print(0)
    exit(0)

b = 0
for k in range(N):
    if S[k] == "#":
        b = k
        break
w = 0
for k in range(N):
    if S[k] == ".":
        w = k

print(min(t,S.count("#"),S[:w+1].count("#"),S[b:].count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
t = s[::1]
ans = 0
cnt = 0
cnt2 = 0
res = 0
for i in s:
    if i==".":
        ans += 1
    else:
        res += 1
for i in s:
    if i==".":
        cnt += 1
    else:
        break
for i in t:
    if i=="#":
        cnt2 += 1
    else:
        break

print(min(ans-cnt,res-cnt2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
ans = 0

for i, v in enumerate(s):
    if i == 0:
        if v == '#':
            ans += 1
            c = 1
        continue
    if c:
        c = 0
        continue
    if v == '#' and s[i-1:i] == '#':
        ans += 1
        c = 1
    else:
        c = 0

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(1,N,1):
    if S[i-1] == "#" and S[i] == ".":
        cnt +=1
bcount = S.count("#")
wcount = S.count(".")
if bcount > wcount:
    print(cnt)
else:
    print(min(bcount,wcount))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cmp1,cmp2 = 0,0

if s.count('.') == n:
    print('0')
else:
    cmp1 = s[s.index('#'):].count('.')
    cmp2 = s[:s[::-1].index('#')].count('#')
    print(min(cmp1,cmp2))

Submission status: Wrong Answer

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

flug = False
cnt = 0
for i,n in enumerate(S):
    if S[i]=='#':
        flug=True
    else:
        if flug and S[i]=='.':
            cnt+=1
        else:
            flug=False
    
print(cnt)