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 sys,copy
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

n = int(input())
S = input()
W = [0]*(2*10**5+1)
B = [0]*(2*10**5+1)
for i in range(n):
    if S[i] == '.':
        W[i] = 1
    else:
        B[i] = 1
for i in range(1,2*10**5+1):
    W[i] += W[i-1]
    B[i] += B[i-1]
res = INF
for i in range(2*10**5+1):
    ans = W[-1]-W[i]+B[i]
    if ans <= res:
        res = ans
print(res)

Submission status: Wrong Answer

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

ans1 = 0
ans2 = 0


for i in range(n):
    if s[i] == '.':
         ans1 += 1
    else :
        ans2 += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flag = False
ans = 0
l = []
if S != '' :
    if S[0] == '.' :
        firstIsw = True
    else :
        firstIsw = False

cnt = 1
for i in range(1, len(S)) :
    if S[i] == S[i - 1]:
        cnt += 1
    else :
        l.append(cnt)
        cnt = 1
    if i == len(S) - 1 :
        l.append(cnt)

flag2 = False

if firstIsw :
    for i in range(1, len(l)) :
        if flag2 :
            if i % 2 == 0 :
                ans += l[i]
        else :
            if i % 2 == 1 :
                if i + 1 != len(l) :
                    if l[i] <= l[i + 1] :
                        ans += l[i]
                    else :
                        flag2 = True
else :
    for i in range(len(l)) :
        if flag2 :
            if i % 2 == 1 :
                ans += l[i]
        else :
            if i % 2 == 0 :
                if i + 1 != len(l) :
                    if l[i] <= l[i + 1] :
                        ans += l[i]
                    else :
                        flag2 = True

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if len(set(S)) == 1:
    print(0)
    exit()

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
s_end=s[1:]
print(min(s_end.count('#'),s_end.count('.')))

Submission status: Wrong Answer

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

count_if_all_white = 0
for c in S:
    if c == "#":
        count_if_all_white += 1

count_if_contain_black = None
for i in range(len(S)+1):
    l_count = sum([1 for c in S[0:i] if c == "#"])
    r_count = sum([1 for c in S[i:len(S)+1] if c == "."])
    count = l_count + r_count
    if not count_if_contain_black:
        count_if_contain_black = count
    else:
        count_if_contain_black = min(count_if_contain_black, count)

print(min(count_if_all_white, count_if_contain_black))

Submission status: Wrong Answer

Solution code:
import numpy as np
n=2
a=[input() for i in range(n)]
N=int(a[0])
S=list(a[1])

kazuXD=0
flg=0
kazu=0
for i in range(N):
  if flg==0:
    if S[i]==".":
      kazu+=1
    else:
      flg=1
flg=0
for i in range(N):
  if i>kazu:
    if S[i]==".":
      S[i]="#"
      kazuXD+=1
  
print(kazuXD)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = '##.#'
b = '##..'
c = '.#.#'
d = '.#..'
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 + '#'
    LS = list(S)
    t = S[:4]
    e = 3
    N += 2
    while True:
        if t == a:
            ans += 1
            LS[e-1]  = '#'
        elif t == b:
            ans += 1
            LS[e-1]  = '#'
        elif t == c:
            ans += 1
            LS[e-1] = '#'
        elif t == d:
            ans += 1
            LS[e-2] = '.'
        e += 1
        if e > N-1:
            break
        t = t[1:] + LS[e]
    print(ans)

Submission status: Wrong Answer

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


index = 0
shCounter = 0
jhC = 0
while index < len(listS):
    if listS[index] == "#":
        jhC += 1
    else:
        shCounter += jhC
        jhC = 0
    index += 1

index = len(listS)-1
dotCounter = 0
jhC = 0
while index > -1:
    if listS[index] == ".":
        jhC += 1
    else:
        dotCounter += jhC
        jhC = 0
    index -= 1

print(min(shCounter, dotCounter))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
shape = S.split("#")[1:]
count = 0
nums = []
for i in range(len(shape)):
    if shape[i]==".":
        count+=1
        if i==len(shape)-1:
            nums.append(count)
    else:
        nums.append(count)
        count=0
ans = sum([1 if num==1 else num-1 for num in nums])
print(ans)

Submission status: Wrong Answer

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

W = [0 for k in range(N+1)]
B = [0 for k in range(N+1)]

for k in range(N):
    if S[k] == "#":
        B[k] = B[k-1] + 1
    else:
        B[k] = B[k-1]

W[0] = t
for k in range(1,N):
    if S[k] == ".":
        W[k] = W[k-1] - 1
    else:
        W[k] = W[k-1]
ans = N
for k in range(N):
    ans = min(ans,W[k]+B[k])
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

stack = []


for i in range(N):
    if S[i] == '.':
        stack.append(i)
        j = i

if stack:
    ans = min(j - (len(stack) - 1), len(stack))
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())[::-1]
white = False
cnt = 0
for i in range(n):
    if s[i] == ".":
        white = True
    elif white:
        cnt += 1
black = False
s = s[::-1]
cnt2 = 0
for i in range(n):
    if s[i] == "#":
        black = True
    elif black:
        cnt2 += 1

print(min(cnt, cnt2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# coding: UTF-8

def check(n,s):
    count = 0
    for i in range(1,n):
        if s[i-1] == "#" and s[i] == ".":
            count += 1
    return count

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

b = S.count("#")
w = S.count(".")
print(check(N,S))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
A=[]
for i in S:
    A.append(i)
B=A
count1=0
count2=0
for i in range(N-1):
    if (A[i]=="#")and( A[i+1]=="."):
        A[i+1]="#"
        count1+=1
for i  in range(N-1):
    if B[ i]  =="#":
        B[i]="."
        count2+=1
ans=min(count1,count2)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 19:26:31 2019
Tenka1C
@author: maezawa
"""

n = int(input())
s = input()
#n = len(s)

cnt = 0
k = -1
for i in range(n):
    if s[i] == '#':
        k = i
        break
if k == n-1:
    pass
elif k == -1:
    pass      
else:
    for j in range(k, n):
        if s[j] == '.':
            cnt += 1


cnt2 = 0
k2 = -1
for i in range(n):
    if s[i] == '.':
        k2 = i
        break
if k2 == n-1:
    pass
elif k2 == -1:
    pass      
else:
    for j in range(k2, n):
        if s[j] == '#':
            cnt2 += 1

print(min(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
import re
N = int(input())
S = input()
S = re.sub(r"#*$","",S)
dot = S.count(".")
sha = len(S) - dot
print(min(dot, sha))

Submission status: Wrong Answer

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

count = 0
for i in range(len(s)-1):
    if s[i] == '#' and s[i+1] == '.':
        if i == 0:
            s[i] = '.'
            count += 1
        elif i == len(s) -2:
            s[i+1] = '#'
            count += 1
        else:
            if s[i+2] == '.':
                if s[:i+1].count('#') < s[i:].count('.'):
                    s[:i] = '.' * len(s[:i])
                    count += len(s[:i])
            else:
                s[i+1] = '#'
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
# . が white
# # が black
right="#"

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

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

#print(S[f_sharp:l_dot+1])
sharp = S[f_sharp:l_dot+1].count("#")
dot = S[f_sharp:l_dot+1].count(".")
print(min(sharp, dot))

Submission status: Wrong Answer

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

for k in range(N):
    if S2[k] == ".":
        id2 = k
        break
for l in range(id2, N):
    if S2[l] == "#":
        c2 += 1
print(min(c1, c2))

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

# count black on right
countX=0
for l in reversed(S):
	if l == "#":
		countX+=1
	else:
		break

countY=0
for l in S:
	if l == ".":
		countY+=1
	else:
		break
count2=N-count-countY
N-=countX
count-=countX
print(min([count,count2]))

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):
        diff = li[i+1] - li[i] - 1
        if diff <= li[i] + 1:
            sum += diff
        else:
            sum += li[i] + 1
    print(sum)

Submission status: Wrong Answer

Solution code:
def chec(s):
    clis = 0
    lef = 0
    rig = 0
    rtmp = 0
    ltmp = 0
    for i in range(len(s)):
        if i+1 != len(s) and s[i] == '#' and s[i+1] == '.' :
            clis+= 1
            rtmp = i + 1
            ltmp = i
            while ltmp != 0 and s[ltmp] == s[ltmp-1]:
                lef += 1
                ltmp -= 1
            while rtmp + 1 != len(s) and s[rtmp] == s[rtmp+1]:
                rig += 1
                rtmp += 1
            clis += min(lef,rig)
            lef = 0
            rig = 0
            rtmp = 0
            ltmp = 0
                
    return clis


n = int(input())
s = list(input())
print(chec(s))

Submission status: Wrong Answer

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

N = int(input())
S = input()
s_count = 0
d_count = 0
c1 = 0
for i in S:
    if i == "#":
        s_count+=1
    else:
        c1+=s_count
        s_count=0
        d_count+=1
        
print(min(c1,d_count))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
try:
    first_black = S.index('#')
except ValueError:
    first_black = N - 1
try:
    last_white = N - S[::-1].index('.') - 1
except ValueError:
    last_white = 0
target = S[first_black:last_white]
length = last_white - first_black + 1
black = target.count('#')
print(min(black, length - black))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [i for i in input()]
for i in range(N):
    if(S[i]=='#'):
        break
s = S[i:]
a = s.count('.')
print(min(a,len(s)-a))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
left=0
right=0
for left in range(n-1):
  if s[left]=='#' and s[left+1]=='.':
    right=left+1
    while s[right]=='.' and right < n-1:
        right+=1
    cnt+=right-1-left
    left=right+1
  else:
    left+=1

if s.count('.')==n:
  print(0)
else:  
  print(cnt+1 if s.count('#')>0 and s[-1]=='.' else cnt)

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
white_change = 0 if s.count("#") == 0 else s[s.index("#"):].count(".")
print(white_change if white_change < s.count("#") else s.count("#"))

Submission status: Wrong Answer

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

ans = 2*10**5
c_b = 0
c_w = 0
for i in range(N):
    if S[i] == '#':
        c_b += 1
    else:
        c_w += 1

ans = min(ans, c_b, c_w)

count = 0
for i in range(N):
    if N <= N//2:
        if S[i] == '#':
            count += 1
    elif N > N//2:
        if S[i] == '.':
            count += 1

print(min(ans, count))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
 
a=s.count(".")
tmp=s.rfind(".")
if tmp==-1:
  print(0)
  exit()
b=s[0:tmp].count("#")
tmp=s.find("#")
if tmp==-1:
  print(0)
  exit()
c=s[tmp:len(s)-1].count(".")
print(a,b,c)
print(min(a,b,c))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
white = '.'
black = '#'

cnt = 0
for i in S:
    if(i==black):
        break
    else:
        cnt += 1
#print(cnt)
#print(S)
bS = S[cnt:]
#print(S)

black_chg_cnt = 0
white_chg_cnt = 0
for i in bS:
    if(i==white):
        black_chg_cnt += 1
    else:
        white_chg_cnt += 1

if(black_chg_cnt<white_chg_cnt):
    print(black_chg_cnt)
else:
    print(white_chg_cnt)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
ans=0
if s.count(".")==n:
    print(0)
    sys.exit()
for i in range(len(s)):
    if s[i]=="#":
        print(min(s[i+1:].count("."),s[i:].count("#")))
        break

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    S = list(_ for _ in input())

    S_num = []
    index = 0 
    now = ''
    if(S[0]=='#'):
        S_num.append(1)
        now = '#'
    else:
        S_num.append(-1)
        now = '.'
        
    for i in range(1,N):
        if(S[i]=='#' and now =='#'):
            S_num[index] +=1
        elif(S[i]=='.' and now =='.'):
            S_num[index] +=-1
        elif(S[i]=='#' and now !='#'):
            S_num.append(1)
            now = '#'
            index +=1
        elif(S[i]=='.' and now !='.'):
            S_num.append(-1)
            now = '.'
            index +=1
    # print(S_num)
    ans = 0
    # ###.#.. → 3,-1,1,-2 → 5,-2
    # #...#.. → 1,-3,1,-2 → 1,-2
    for i in range(len(S_num)-1):
        if(S_num[i]>0 and S_num[i+1]<0):
            ans += min(S_num[i],-S_num[i+1])
            if((S_num[i] > -S_num[i+1]) and i+2 < len(S_num)-1):
                S_num[i+2] += S_num[i] -S_num[i+1]                        
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=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] :
        continue
    else:
        count +=1
print(count)

Submission status: Wrong Answer

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

B = 0
W = 0

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if s.count("#")==0 or s.count(".")==0:
    print(0)
    exit()
bi=s.index("#")
wi=n-s[::-1].index(".")
if wi<bi:
    print(0)
    exit()
bc=s[bi:wi].count("#")
print(min(bc,wi-bi-bc))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(S) == 0:
	print(0)
else:
	for n in range(N):
		if S[n:n+2] == "#." :
			M = n+1
			break
		else:
			M = len(S)+1
	for j in range(N):
		if S[-(j+1)] == "#":
			B_end += 1
		if S[-(j+1)] == ".":
			break
	
	WB = S[M:].count(".")
	BW = S[M:].count("#") - B_end
#	print("B_end = " + str(B_end))
#	print(S[M-1:].count("#"))
#	print(min(WB , BW))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10000000)


def check_and_back_or_go_to(li, ind, N, counter, white_charge):
    back = True
    # print('see {} {} and {} counter{}'.format(ind, li[ind - 1], li[ind], counter))
    if ind == 0:
        return counter

    # access
    if li[ind - 1] == '#' and li[ind] == '.':
        c = check_and_back_or_go_to(li, ind - 1, N, counter + 1 + white_charge, 0)
        return c
    elif li[ind - 1] == '.' and li[ind] == '.':
        return check_and_back_or_go_to(li, ind - 1, N, counter, white_charge + 1)
    else:
        c = check_and_back_or_go_to(li, ind - 1, N, counter, white_charge)
        return c


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

Submission status: Wrong Answer

Solution code:
input()
s = input()
ans = s.count("#.")
ans += s.count("##.")
ans += s.count("#..")

print(ans)

Submission status: Wrong Answer

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

x=0
a=0
b=0

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

if a==N:
    print("0")
elif b==N:
    print("0")
elif a>=b:
    x=N-a
    print(x)
else:
    x=N-b
    print(x)

Submission status: Wrong Answer

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


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






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

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

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

Submission status: Wrong Answer

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

sp_pos = S.find('#')
dot_num = S[sp_pos+1:].count('.')

dot_pos = S.rfind('.')
sp_num = S[:dot_pos].count('#')

hl = len(S) // 2
hl_num = S[:hl].count('#') + S[hl:].count('.') 

print(min(dot_num, sp_num, hl_num))

Submission status: Wrong Answer

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

ans = 0
index = 0

if S.count("#") == 0:
    print(ans)
    exit()

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

ans += N - index - 1

ans += S[:index].count(".")

another_ans = S.count("#")

if another_ans < ans:
    print(another_ans)
    exit()

print(ans)

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s0 = input()
s = s0
c1 = 0
c2 = 0
while True:
  t = re.subn(r'#\.', "##", s)
  s = t[0]
  c1 += t[1]
  if t[1]==0:
    break
s = s0
while True:
  t = re.subn(r'#\.', "..", s)
  s = t[0]
  c2 += t[1]
  if t[1]==0:
    break
if c1 > c2:
  print(c2)
else:
  print(c1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input().rstrip()
s = s.rstrip('#')
s = s.lstrip('.')
if (len(s) == 0):
    print(0)
    exit()

print(s.count('.'))

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 == '#':
        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
    ct = 1
    for i in S[idx+1:]:
        if i == '.':
            break
        ct += 1
    c = ct
    for i in S[idx+ct+1:]:
        if i == "#":
            break
        ct += 1
    c += S[idx+ct+1:].count('.')
    ans = min(a, b)
    ans = min(ans, c)
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

b=s.count('#')
# w=s.count('.')

ans=0
sflag=False
pflag=False
snum=0
pnum=0

for i in range(n):
    if s[i] == '#' and sflag and pflag:
        ans+=min(snum,pnum)
        snum=0
        pnum=0
        sflag=False
        pflag=False

    elif s[i] == '#':
        sflag = True
        snum+=1

    elif sflag == True and s[i] == '.':
        pflag=True
        pnum+=1

    elif ans>=b:
        break

#print(min(b,w))
print(min(b,ans+pnum))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().rstrip()
index = S.find("#")
answer = 0
if index == -1:
    print(0)
    exit()
else:
    answer = S[index:].count(".")
index = S.rfind(".")
if index == -1:
    print(0)
    exit()
else:
    answer = S[:index+1].count("#") if S[:index+1].count("#")<answer else answer
index_s = S.rfind("#")
S_new1 = S[:index_s]
S_new1 = S[:S_new1.rfind(".")+1]
S_new2 = S[index-1:]
res = S_new2.count(".") + S_new1.count("#")
answer = res if res < answer else answer
print(answer)

Submission status: Wrong Answer

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

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

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

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

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



print(min(ans0,ans1))

Submission status: Wrong Answer

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

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

idx_list = [0, N]
for i in range(N-1):
  if S[i] == "." and 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())
ans = 0
for i in range(n-1):
    if s[i] == "#" and s[i+1] == ".":
        s[i+1] = "#"
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import re

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

after_b_s = re.sub('^\.*(#.+)', r'\1', s)
w2b_cnt = 0 if '#' not in after_b_s else after_b_s.count('.')
b2w_cnt = 0 if '.' not in after_b_s else after_b_s.count('#')

print(min(w2b_cnt, b2w_cnt))

Submission status: Wrong Answer

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

kuro = s.count("#")
shiro = s.count(".")
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(min(count,kuro,shiro))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = 0
w = 0

for i in range(n):
    if(s[i] == "#"):
        for j in range(i, n):
            if(s[j] == "#"):
                b += 1
            else:
                w += 1
        break

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
s = input()
ans = 0
i = 0
c = 0

while i < n:
    if s[i:i+1] == '#':
        c += 1
        i += 1
        while s[i:i+1] == '#':
            c += 1
            i += 1
        ans += math.floor(c/2)
        c = 0
    else:
        i += 1

if s[0:2] == '#.':
    ans += 1

print(ans)

Submission status: Wrong Answer

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

ideal1 = '#' * n
ideal2 = '.' * n
ideal3_dotnum = s.rfind('.') + 1
ideal3 = '.' * ideal3_dotnum + '#' * (n-ideal3_dotnum)

cnt1, cnt2, cnt3 = 0, 0, 0
for i_s, i1, i2, i3 in zip(s, ideal1, ideal2, ideal3):
  if i_s != i1:
    cnt1 += 1
  if i_s != i2:
    cnt2 += 1
  if i_s != i3:
    cnt3 += 1

print(min(cnt1, cnt2, cnt3))

Submission status: Wrong Answer

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

l = []
for i in S:
	if i == '#':
		l.append(0) #黒
	else:
		l.append(1) #白

r = l[:]
ans1 = 0
for i in range(len(l)):
	if l[i:i+2] == [0, 1]:
		ans1 = ans1 + 1
		l[i+1] = 0
		

ans2 = 0

for i in range(len(r)):
	if r[i:i+2] == [1,0]:
		ans2 = ans2 + 1
		r[i+1] = 1

ans = ans1 if ans1 < ans2 else ans2
print(ans)

Submission status: Wrong Answer

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

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

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

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

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

res3 = N - max(b, w)

print(min(res1, res3))

Submission status: Wrong Answer

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

    black_cnt = S.count('#')
    white_cnt = S.count('.')

    if black_cnt == 0 or white_cnt == 0:
        print(0)
    else:
        print(min(black_cnt, white_cnt))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    next_black_num = 0
    pre_stone = "."

    for s in S:
        if pre_stone == "#" and s == ".":
            next_black_num += 1
            pre_stone = "#"
        else:
            pre_stone = s

    print(min([next_black_num, N - next_black_num]))


if __name__ == '__main__':
    main()

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():
    global S
    ans =0
    numB = 0
    leftMostW = -1
    firstB = N
    for i in range(len(S)):
        if S[i]=="#":
            firstB = i
            break
    if firstB == N:
        return 0
    S = S[firstB:]

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

    return min(numB,leftMostW+1-numB)



print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
k = -1
for i in range(N):
    if s[i] == "#":
        k = i
        break
if k == -1:
    print(0)
else:
    if s[-1]=="#":
        print(min(s[k:N].count("."), s.count("#")-1))
    else:
        print(min(s[k:N].count("."), s.count("#")))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count1=0
count2=0
s=list(S)

for i in range(N-1):
    if s[i]!=s[i+1]:
        s[i+1]=s[i]
        count1+=1
        
for i in range(N-1):
    if s[i]!=s[i+1]:
        s[i]=s[i+1]
        count2+=1

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
sw=s
t=0
k=0
for i in range(n-1):
    if s[i+1]==".":
        if s[i]=="#":
            t+=1
            s[i+1]="#"

for i in range(n-1):
    if sw[i]=="#":
        if sw[i+1]==".":
            k+=1
            sw[i+1]="#"
print(max(t,k))