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:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
	
def main():
	N = int(input())
	S = input()
	
	if N == 1:
		print(0)
		sys.exit()
	
	kuro = []
	for i, val in enumerate(S):
		if i == 0:
			if val == "#":
				kuro.append(1)
			else:
				kuro.append(0)
			continue
		if val == "#":
			kuro.append(kuro[i-1] + 1)
		else:
			kuro.append(kuro[i-1])
	
	shiro = [0 for _ in range(N)]
	for i in range(N-1, -1, -1):
		if i == N-1:
			if S[i] == ".":
				shiro[i] = 1
			else:
				shiro[i] = 0
			continue
		if S[i] == ".":
			shiro[i] = shiro[i+1] + 1
		else:
			shiro[i] = shiro[i+1]
			
	ans = -1
	for i in range(N):
		tmp = -1
		if i == 0:
			tmp = shiro[0]
		elif i == N-1:
			tmp = kuro[N-1]
		else:
			tmp = kuro[i] + shiro[i+1]
			
		if ans > tmp or ans == -1:
			ans = tmp
	
	#print(kuro)
	#print(shiro)
	print(ans)
	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

stones = []

for c in S:
    stones.append(c)

stones2 = stones.copy()

k = 0

for i,stone in enumerate(stones):
    if i < len(stones) - 1:
        if stone == "#":
            if stones[i+1] == ".":
                stones[i+1] = "#"
                k += 1
l = 0
for i,stone in enumerate(stones2[::-1]):
    a = len(stones) - i -1
    if a != 0:
        if stone == ".":
            if stones[a-1] == "#":
                stones[a-1] = "."
                l += 1


print(k if k < l else l)

Submission status: Wrong Answer

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

stones = []

for c in S:
    stones.append(c)

k = 0

for i,stone in enumerate(stones):
    if i < len(stones) - 1:
        if stone == "#":
            if stones[i+1] == ".":
                stones[i+1] = "#"
                k += 1
print(k)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
	
def main():
	N = int(input())
	S = input()
	
	kuro = []
	for i, val in enumerate(S):
		if i == 0:
			if val == "#":
				kuro.append(1)
			else:
				kuro.append(0)
			continue
		if val == "#":
			kuro.append(kuro[i-1] + 1)
		else:
			kuro.append(kuro[i-1])
	
	shiro = [0 for _ in range(N)]
	for i in range(N-1, -1, -1):
		if i == N-1:
			if S[i] == ".":
				shiro[i] = 1
			else:
				shiro[i] = 0
			continue
		if S[i] == ".":
			shiro[i] = shiro[i+1] + 1
		else:
			shiro[i] = shiro[i+1]
			
	ans = 1000000000000000
	for i in range(N):
		tmp = -1
		if i == 0:
			tmp = shiro[0]
		elif i == N-1:
			tmp = kuro[N-1]
		else:
			tmp = kuro[i] + shiro[i+1]
		if ans > tmp:
			ans = tmp
	
	#print(kuro)
	#print(shiro)
	print(ans)
	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
	
def main():
	N = int(input())
	S = input()
	
	kuro = []
	for i, val in enumerate(S):
		if i == 0:
			if val == "#":
				kuro.append(1)
			else:
				kuro.append(0)
			continue
		if val == "#":
			kuro.append(kuro[i-1] + 1)
		else:
			kuro.append(kuro[i-1])
	
	shiro = [0 for _ in range(N)]
	for i in range(N-1, -1, -1):
		if i == N-1:
			if S[i] == ".":
				shiro[i] = 1
			else:
				shiro[i] = 0
			continue
		if S[i] == ".":
			shiro[i] = shiro[i+1] + 1
		else:
			shiro[i] = shiro[i+1]
			
	ans = 10000000
	for i in range(N):
		tmp = -1
		if i == 0:
			tmp = shiro[0]
		elif i == N-1:
			tmp = kuro[N-1]
		else:
			tmp = kuro[i] + shiro[i+1]
		if ans > tmp:
			ans = tmp
	
	#print(kuro)
	#print(shiro)
	print(ans)
	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
l = int(input())
ss = input()
dn = ss.count('.')
dc = 0
if l == dn:
    print(0)
else:
    for i in range(l):
        dc = dc + 1 if ss[i] == '.' else dc
        if dn/2 < dc:
            bits = ''.join(list(map(lambda s: '0' if s == '.' else '1', ss)))
            sbits0 = ''.join('0' for _ in range(dc))
            sbits1 = ''.join('1' for _ in range(l-dc))
            c0 = bin(int(bits, 2) ^ int(sbits0 + sbits1,2)).count('1')
            sbits = ''.join('1' for _ in range(l))
            c1 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
            print(c0 if c0 < c1 else c1)
            break

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w='.'
b='#'
ans=[]
bc=s.count(b)
wc=n-bc
WC=n-bc
BC=0
for i in range(n):
    if b==s[i]:
        if BC+WC<0:
            pass
        else:
            ans+=[BC+WC]
        BC+=1
    else:
        WC-=1
print(0 if ans==[] else min(ans))

Submission status: Wrong Answer

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

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

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

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = float("INF")
for i in range(1, N + 1):
    black = S[:i].count("#")
    white = S[i:].count(".")

    ans = min(ans, black + white)

    if ans == 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
black_appered = False
ans = 10**9
count = s.count('.')
if count==0:
    print(0)
else:
    # [BBB...WWW...]の組を抽出する
    for x in s:
        if x =='.':
            count -= 1
        else:
            count += 1
        ans = min(ans,count)
        # print(ans)
        # print("===")
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
black_appered = False
ans = 10**9
count =s.count('.')
# [BBB...WWW...]の組を抽出する
for x in s:
    if x =='.':
        count -= 1
    else:
        count += 1
    ans = min(ans,count)
    # print(ans)
    # print("===")
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
list1=[0]*N
for i in reversed(range(N)):
    if i==N-1 and S[i]==".":
        list1[i]+=1
    elif i==N-1:
        list1[i]=0
    elif S[i]==".":
        list1[i]=list1[i+1]+1
    else:
        list1[i]=list1[i+1]
print(list1)    
list2=[]
for i in range(N+1):
    if i==0:
        tmp=N-list1[0]
    elif i==N:
        tmp=list1[0]
    else:
        tmp=i-list1[0]+2*list1[i]
    print(tmp)
    list2.append(tmp)
print(min(list2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
print(min(S.count("#"), S.count(".")))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n):
  if s[i]=='#':
    ans=s[i:].count('.')
    break
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
src = "........."
costs = [reduce(lambda x,y: x+(1 if y=="#" else 0), src[:i], 0) + reduce(lambda x,y: x+(1 if y=="." else 0), src[i:], 0) for i in range(len(src))]
costs.append(reduce(lambda x,y: x+(1 if y=="#" else 0), src, 0))
print(min(costs))

Submission status: Wrong Answer

Solution code:
from functools import reduce
input()
src = input()
costs = [reduce(lambda x,y: x+(1 if y=="#" else 0), src[:i], 0) + reduce(lambda x,y: x+(1 if y=="." else 0), src[i:], 0) for i in range(len(src))]
costs.append(reduce(lambda x,y: x+(1 if y=="#" else 0), src, 0))
print(costs)
print(min(costs))

Submission status: Wrong Answer

Solution code:
def CountToAllBlack(s):
    return s.count('.')

def CountToAllWhite(s):
    return s.count('#')


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

firstBlack = S.find('#')
count = min(CountToAllBlack(S[firstBlack:]), CountToAllWhite(S[:N-2]))
print(count)

Submission status: Wrong Answer

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

for i in range(len(s)):
    if i+1< len(s):
        if s[i]=="#" and s[i+1]==".":
            c += 1

print(c)

Submission status: Wrong Answer

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

a,b = 0,0
for i in s:
    if i == '.':
        a += 1 #白の個数
    else:
        b += 1 #黒の個数

min_c = c = 10**10
if s[0] == '.':
    counta, countb = 0, 0
    for k, i in enumerate(s):
        if s[k] == '.':
            counta += 1
        if s[k] == '#':
            countb += 1
            c = (a - counta) + (countb - 1)
        if min_c > c:
            min_c = c
        
print(min(a,b, min_c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a,b = 0,0
for i in s:
    if i == '.':
        a += 1
    else:
        b += 1
print(min(a,b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

white=S.count(".")
countb=0
ans=len(S)

for i in range (len(S)):
  if S[i]==".":
    white -=1
  else:
    countb +=1 
  ans=min(ans, countb+white)

print(ans)

Submission status: Wrong Answer

Solution code:

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

white=S.count(".")
countb=0
ans=10**9

for i in range (len(S)):
  if S[i]==".":
    white -=1
  else:
    countb +=1 
  ans=min(ans, countb+white)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=2*10**5

if S[0]==".":
    for i in range(0,N):
        new_ans=0
        for m in range(0,i):
            if S[m]=="#":
                new_ans+=1
        for k in range(i,N):
            if S[k]==".":
                new_ans+=1
        ans=min(ans,new_ans)
        ans-=1
else:
    for i in range(0,N):
        new_ans=0
        for m in range(0,i):
            if S[m]=="#":
                new_ans+=1
        for k in range(i,N):
            if S[k]==".":
                new_ans+=1
        ans=min(ans,new_ans)    

print(ans)

Submission status: Wrong Answer

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

ans=N
white=S.count(".")
countb=0

for i in range (N):
  if S[i]==".":
    white -=1
  else:
    countb +=1 
  ans=min(ans, countb+white)

print(ans)

Submission status: Wrong Answer

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

minimum=N
white=S.count(".")
black=S.count("#")
countw=0
countb=0
for i in range (N):
  if S[i]==".":
    countw +=1
  else:
    countb +=1
  minimum=min(minimum, countb+white-countw)
print(minimum)

Submission status: Wrong Answer

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

r_c = S.count('.')
l_c = 0
sum = []

for i in S:
	if i == '#':
		l_c = l_c + 1
	elif i == '.':
		r_c = r_c - 1
	sum.extend([l_c + r_c])
print(min(sum))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s_list = list(s)
count1 = 0
count2 = 0

for i in range(n):
    if(s_list[i] == '#'):
        for j in range(0,n-i-1):
            #print(s_list[j+i])
            #print(j)
            if(s_list[j+i+1] == '.'):
                #print("count")
                count1 = count1 + 1
        break


for i in range(n):
    if(s_list[i] == '#'):
        count2 = count2 + 1


if(count1 < count2):
    print(count1)
else:
    print(count2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
S = input()
black = 0
white = 0
l = [] # 
ans=float('inf') 

for s in S:
    if s == "#":
        black += 1
    else:
        white += 1

if white == 0:
    print(0)
    
else:
    leftBlack = 0
    rightWhite = white
    for s in S:
        if s == "#":
            leftBlack += 1
        else:
            rightWhite -= 1
            
        ans = min(ans, (leftBlack + rightWhite))
        
    print(ans)

Submission status: Wrong Answer

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

l_sum = []
r_sum = []
sum_list = []

l_c = 0
r_c = 0

for i in range(len(S)):
	if S[i] == '#':
		l_c = l_c + 1
	l_sum.extend([l_c])
	if S[len(S)-1-i] == '.':
		r_c = r_c + 1
	r_sum.insert(0,r_c)

sum_list = [x + y for (x,y) in zip(l_sum,r_sum)]
print(min(sum_list))

Submission status: Wrong Answer

Solution code:
N=input();S=input();
b_num, w_num = 0, 0
if '#' in S:
    S = S[S.index('#'):]
    w_num = S.index('#')
if '.' in S:
    R = S[::-1]
    R = R[R.index('.'):]
    b_num = R.index('.')
    S = R[::-1]

try:
    print(min(S.count('.') + w_num, S.count('#') + b_num))
except ValueError:
    print(0)

Submission status: Wrong Answer

Solution code:
N=input();S=input();
b_num, w_num = 0, 0
if '#' in S:
    S = S[S.index('#'):]
    w_num = S.index('#')
if '.' in S:
    R = S[::-1]
    R = R[R.index('.'):]
    S = R[::-1]
    b_num = S.index('.')

try:
    print(min(S.count('.') + w_num, S.count('#') + b_num))
except ValueError:
    print(0)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    first_black = -1
    for i, s in enumerate(S):
        if s == '.':
            pass
        else:
            first_black = i
            break
    sum = 0
    if 0 <= first_black < N-1:
        for i in range(first_black+1, N):
            if S[i] == '.':
                sum += 1
            else:
                pass
    else:
        pass
    print(sum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    first_black = -1
    for i in range(N):
        if S[i] == '.':
            pass
        else:
            first_black = i
            break
    sum = 0
    if first_black >= 0:
        for i in range(first_black+1, N):
            if S[i] == '.':
                sum += 1
            else:
                pass
    else:
        pass
    print(sum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=input();S=input();
if '#' in S:
    S = S[S.index('#'):]
if '.' in S:
    R = S[::-1]
    R = R[R.index('.'):]
    S = R[::-1]

try:
    print(min(S.count('.'), S.count('#')))
except ValueError:
    print(0)

Submission status: Wrong Answer

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

if "#" in s and "." in s:
	string = s[s.index("#"):s.rindex(".")+1]
	black = string.count("#")
	white = len(string) - black
	print(min(white,black))
else:
	print(0)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    for i in range(N):
        if S[i] == '.':
            pass
        else:
            first_black = i
            break
    sum = 0
    for i in range(i+1, N):
        if S[i] == '.':
            sum += 1
        else:
            pass
    print(sum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=input();S=input();print(min(S[S.index('#'):].count('.'),S[S.index('#'):].count('#')) if '#'in S else 0)

Submission status: Wrong Answer

Solution code:
N=input();S=input();print(min(S.count('.'),S.count('#')))

Submission status: Wrong Answer

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

count=S.count(".")
if "#" in S:
  first=S.index("#")

print(count-first) if "#" in S else print(N)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

# .......####### という形を目指す

#累積和を計算
sum_black = [0]
sum_white = [0]
for n in range(0,N):
    if S[n] == '#': #black
        sum_black.append(sum_black[n] + 1)
        sum_white.append(sum_white[n] + 0)
    else:
        sum_black.append(sum_black[n] + 0)
        sum_white.append(sum_white[n] + 1)

num_min = N
for n in range(0,N):
    num = sum_black[n] + (sum_white[-1] - sum_white[n]) 
    if num < num_min:
        num_min = num

print(num_min)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

# .......####### という形を目指す

#累積和を計算
sum_black = [0]
sum_white = [0]
for n in range(0,N):
    if S[n] == '#': #black
        sum_black.append(sum_black[n] + 1)
        sum_white.append(sum_white[n] + 0)
    else:
        sum_black.append(sum_black[n] + 0)
        sum_white.append(sum_white[n] + 1)

num_min = N
for n in range(0,N):
    num = sum_black[n] + (sum_white[n] - sum_white[-1]) 
    if num < num_min:
        num_min = num

print(num_min)

Submission status: Wrong Answer

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

all_Black = S.count('.')
all_White = S.count('#')
White_Black = all_Black + all_White

l_sum = []

for i in range(len(S)):
    #print(S[0:i].count('#'),S[i:len(S)].count('#'))
    l_sum.extend([S[0:i].count('#')+S[i:len(S)].count('#')])

print(min(all_Black,all_White,White_Black))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

data = []

num_min = N
for i in range(0,N):
    num = S[:i+1].count('#') + S[i+1:].count('.')
    if num < num_min:
        num_min = num

print(num_min)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

nmin = S.find('#.')

if nmin == -1:
    print(0)
else:
    all_to_black = S.count('.')
    all_to_white = S.count('#')

    left = S[:nmin+1]
    right = S[nmin+1:]
    split = left.count('#') + right.count('.')

    print(min(all_to_black, all_to_white, split))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

nmin = S.find('#.')

num_white = S.count('.')
num_black = S.count('#')

num_white_right = S[nmin+1:].count('.')
num_black = S[nmin+1:].count('#')

all_black = num_white
all_white = num_black
split = S[:nmin+1].count('#') + S[nmin+1:].count('.')

otvet = min(all_black, all_white, split)
print(otvet)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

otvet = min(S.count('.'), S.count('#'))

print(otvet)

Submission status: Wrong Answer

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

all_Black = S.count('.')
all_White = S.count('#')
White_Black = all_Black + all_White
if S[0] == '.':
    for i in range(len(S)-1):
        if S[i] == '.' and S[i+1] == '#':
            S.pop(0)
            break
    White_Black = S.count('.')
print(min(all_Black,all_White,White_Black))

Submission status: Wrong Answer

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

all_Black = S.count('.')
all_White = S.count('#')
White_Black = 1000000
if S[0] == '.':
    for i in range(len(S)-1):
        if S[i] == '.' and S[i+1] == '#':
            S.pop(0)
            break
    White_Black = S.count('.')
print(min(all_Black,all_White,White_Black))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
for i in range(n):
    if i == 0:
        ans = 0
        if s[i] == ".":
            flag = False
        else:
            flag = True
    elif not flag:
        if s[i] == "#":
            flag = True
    else:
        if s[i] == ".":
            ans += 1
for i in range(n):
    if i == 0:
        if s[i] == "#":
            ans2 = 1
        else:
            ans2 = 0
            flag = False
    elif i == n - 1:
        if not flag:
            ans2 = 0
    else:
        if s[i] == "#":
            ans2 += 1
        else:
            flag = True
print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
#!/snap/bin/pypy3

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

    whitestones = []
    tmpcount = 0
    for stone in S:
        if stone == '.':
            tmpcount += 1
        whitestones.append(tmpcount)

    totalwhite = whitestones[-1]

    print(min(i - wstone + totalwhite - wstone for i, wstone in enumerate(whitestones, start=1)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
for i in range(n):
    if i == 0:
        ans = 0
        if s[i] == ".":
            flag = False
        else:
            flag = True
    elif not flag:
        if s[i] == "#":
            flag = True
    else:
        if s[i] == ".":
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
black_appered = False
ans = 0
b_cnt = 0
w_cnt = 0
# [BBB...WWW...]の組を抽出する
for i in range(n):
    x = s[i]
    if x == '#': b_cnt +=1
    if x == '.': w_cnt +=1
    if i == n-1 or (x == '#' and 0 < w_cnt and 0 < b_cnt):
        ans += min(b_cnt, w_cnt)
        b_cnt,w_cnt = 0,0
    # print(b_cnt, w_cnt,ans)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
#最初の#
try:
        k = s.index("#")
except:
        k = n
if k == n - 1 or k == n:
        ans = 0
else:
        #print(s[k::])
        ans = s[k::].count(".")
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
for i in range(n):
    if i == 0:
        ans = 0
        flag = False
    elif not flag:
        if s[i] == "#":
            flag
    else:
        if s[i] == ".":
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w='.'
b='#'
ans=[]
bc=s.count(b)
wc=n-bc
WC=n-bc
BC=0
for i in range(n):
    if b==s[i]:

        ans+=[BC+WC]
        BC+=1
    else:
        WC-=1
print(0 if ans==[]or min(ans)<0 else min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
black_appered = False
count = 0
for x in s:
    # 黒が続いたら白に変える
    if x == '.' and black_appered:
        count +=1
        black_appered = False
    if x == '#':
        black_appered=True
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w='.'
b='#'
ans=[]
bc=s.count(b)
wc=n-bc
WC=0
BC=bc-0
for i in range(n):
    if b==s[i]:
        cnt=0
        ans+=[BC+WC-1]
        BC-=1
        WC+=1
print(0 if ans==[] else min(ans))

Submission status: Wrong Answer

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

ans1=0
ans2=s.count('.')
ans=ans1+ans2

for i in range(n):
  if s[i]=='#':
    ans1+=1
  else:
    ans2-=1
  
ans=min(ans,ans1+ans2)

print(ans)

Submission status: Wrong Answer

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

ans = float("inf")
for i in range(len(S)+1):
  left = S[:i].count("/")
  right = S[i:].count(".")
  ans = min(ans, left + right)
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == '.':
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
A = cw[0]
for i in range(N):
    A = min(A, cb[i] + cw[N - 1] - cw[i])
print(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == '.':
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
A = cw[i]
for i in range(N):
    min(A, cw[i] + cb[N - 1] - cb[i])
print(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
ans = S.count("#.")
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
e = S.count('#.')
i = 0
cntB = 0
B = []
cntW = 0
W = []
for i in range(N):
    if S[i] == '#':
        if cntW != 0:
            W.append(cntW)
            cntW = 0
        cntB += 1
        if i == N - 1:
            B.append(cntB)
    else:
        if cntB != 0:
            B.append(cntB)
            cntB = 0
        cntW += 1
        if i == N - 1:
            W.append(cntW)

x = 0
for j in range(e):
    if W[-1] <= B[0]:
        x += W.pop(-1)
    else:
        x += B.pop(0)

print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
if S.count('.') > S.count('#'):
    ans = S.count('#')
    ch = '#'
else:
    ans = S.count('.')
    ch = '.'
if S[0] == '.' and ch == '.':
    ans -= 1
elif S[-1] == '#' and ch == '#':
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
if S.count('.') > S.count('#'):
    ans = S.count('#')
else:
    ans = S.count('.')
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c = []
c.append(S.count('.'))
c[0] += 1 if S[0] == '#' else -1

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

  if S[i] == '.':
    c.append(c[i-1] - 1)

print(min(c))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

itr = 0
for i in s:
  if i not in ".":
    break
  itr += 1

w = 0
b = 0
while itr < n:
  if s[itr] in "#":
    b += 1
  else:
    w += 1
  itr += 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
tmp = 0
for i in range(N):
    if S[i] == '.': tmp += 1 
minVal = tmp
#S[p] -> w
for p in range(N):
    if S[p] == '.': tmp -= 1 
    else: tmp += 1
    minVal = min(minVal, tmp)
print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
minVal = 0
#S[p] -> w
for p in range(N):
    tmp = 0
    for l in range(p):
        if S[l] == '#': tmp += 1
    for r in range(N-p):
        if S[p+r] == '.': tmp += 1
    minVal = min(minVal, tmp)
print(tmp)

Submission status: Wrong Answer

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

all_black_num = S.count('#')
all_white_num = N - all_black_num

left_black_num = 0
left_white_num = 0
if all_black_num == 0 or all_white_num == 0:
    ans = 0
else:
    ans = None
    for i, c in enumerate(S):
        if c == '#':
            left_black_num += 1
        elif c == '.':
            left_white_num += 1
        right_white_num = all_white_num - left_white_num
        right_black_num = all_black_num - left_black_num
        if ans:
            ans = min(ans, left_black_num + right_white_num)
        else:
            ans = left_black_num + right_white_num
        if right_black_num == 0:
            break
print(ans)

Submission status: Wrong Answer

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

all_black_num = S.count('#')
all_white_num = N - all_black_num

left_black_num = 0
left_white_num = 0
if all_black_num == 0 or all_white_num == 0:
    ans = 0
else:
    ans = None
    for i, c in enumerate(S):
        if c == '#':
            left_black_num += 1
        elif c == '.':
            left_white_num += 1
        right_white_num = all_white_num - left_white_num
        if ans:
            ans = min(ans, left_black_num + right_white_num)
        else:
            ans = left_black_num + right_white_num
        if right_white_num in [0, N - i - 1]:
            break
print(ans)

Submission status: Wrong Answer

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

ans = 0
white, black, lastBlack = 0, 0, 0
blackFlag = False
for i in range(N):
    if S[i] == "." and blackFlag:
        white += 1
        lastBlack = 0
    if S[i] == "#":
        black += 1
        lastBlack += 1
        blackFlag = True

print(min(white, black - lastBlack))

Submission status: Wrong Answer

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

all_black_num = S.count('#')
all_white_num = N - all_black_num

left_black_num = 0
left_white_num = 0
if all_black_num == 0 or all_white_num == 0:
    ans = 0
else:
    ans = N
    for c in S:
        if c == '#':
            left_black_num += 1
        elif c == '.':
            left_white_num += 1
        right_white_num = all_white_num - left_white_num
        ans = min(ans, left_black_num + right_white_num)
print(ans)

Submission status: Wrong Answer

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

all_black_num = S.count('#')
all_white_num = N - all_black_num

ans = N
left_black_num = 0
left_white_num = 0
for i, c in enumerate(S):
    if c == '#':
        left_black_num += 1
    elif c == '.':
        left_white_num += 1
    right_white_num = all_white_num - left_white_num
    ans = min(ans, left_black_num + right_white_num)
print(ans)

Submission status: Wrong Answer

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

ans = 0
white, black = 0, 0
blackFlag = 0
for i in range(N):
    if S[i] == "." and blackFlag:
        white += 1
    if S[i] == "#":
        black += 1
        blackFlag = True

print(min(white, black))

Submission status: Wrong Answer

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

white, black = 0, 0 
for i in range(N):
    if S[i] == ".":
        white += 1
    else:
        black += 1

print(min(white, black))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
# b = S.count("#")
w = S.count(".")
black = 0
white = w
ans = 2e5
for i in range(N):
    if S[i] == "#":
        black += 1
    elif S[i] == ".":
        white -= 1
    # print(black,white)
    ans = min(black + white, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from __future__ import print_function
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


n=int(input())
S=list(input())

cnt_temp=0
stack=[]
cnt=0

# # eprint(n)
# # eprint(S)

# for i in range(n):
#     # eprint(i)


# flag=0
# flag2=0
start=0




if S[0] == '.':
    for i in range(n-1):
        if S[i]=='#' and S[i+1]=='.':
            for j in range(i+1,n):
                if S[j] =='.':
                    cnt_temp+=1
            break
else:
    for i in range(n):
        if S[i] == '.':
            cnt_temp+=1

        
# for _ in S:
#     eprint( _ , end="")
# eprint()
        
for i in range(n-1):
    if S[i]=='#' and S[i+1]=='#':
        stack.append(i)
    elif S[i]=='#' and S[i+1]=='.':
        
        S[i]='.'
        cnt+=1
        
        # for _ in S:
            # eprint(_,end="")
        # eprint()
        
        
        
        while stack!=[]:
            temp=stack.pop()
            S[temp]='.'
            cnt+=1
            # for _ in S:
                # eprint(_,end="")
            # eprint()

            
        
# eprint("cnt: ",end="")
# eprint(cnt)
# # eprint("cnt_temp2: ",end="")
# eprint(cnt_temp2)

print(min(cnt,cnt_temp))
            #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #