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 = input()
li = []
i = 0
j = 0
cnt = 0
ans = 0
while i<n:
    while j<n and s[i]==s[j]:
        cnt += 1
        j += 1
    i = j
    li.append(cnt)
    cnt = 0

if s[0] == "#":
    if n%2==0:
        a = sum(li[0::2])
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[-1]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
else:
    if n%2==0:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2]) - li[0]
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b

print(str(ans))

Submission status: Wrong Answer

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

cnt_b = [0 for i in range(N)]    # i番目を含んでそれまでにb，wが何個あるか
cnt_w = [0 for i in range(N)]

if S[0] == "#":
    cnt_b[0] = 1
else:
    cnt_w[0] = 1

for i in range(N - 1):
    if S[i] == "#":
        cnt_b[i + 1] = cnt_b[i] + 1
    else:
        cnt_w[i + 1] = cnt_w[i] + 1

cnt_change = [0 for i in range(N)]
S = "s" + S
for i in range(N):
    cnt_change[i] = S[:i + 1].count("#") + S[i + 1:].count(".")

print(min(cnt_change))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
s = list(input())
b = [0]*(n+1)
c = [0]*(n+1)
a = []
c[0] = s.count(".")
for i in range(n):
    if s[i] == "#":
        b[i+1] = b[i] + 1
        c[i+1] = c[i]
    else:
        c[i+1] = c[i] - 1
        b[i+1] = b[i]
    a.append(b[i+1] + c[i+1])
if "." not in s:
    a.append(0)
elif "#" not in s:
    a.append(0)
print(min(a))

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

    if S[-1] == "#":
        N -= 1

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
c=0
b=0
for i in range(n):
  if s[i]==".":
    c+=1
for i in range(n):
  if s[i]==".":
    b+=1
  else:
    break
print(c-b)

Submission status: Wrong Answer

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

#.#


tmp = 0
ans1 = 0

for s in S:
    if s == ".":
        tmp += 1
    else:
        ans1 += tmp
        tmp = 0




S = S[::-1]
tmp = 0
ans2 = 0

for s in S:
    if s == "#":
        tmp += 1
    else:
        ans2 += tmp
        tmp = 0
    
print (min(ans1,ans2))

Submission status: Wrong Answer

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

X=[]*N
anser=0
k=0
if S[0]==".":
    for i in S:
        if i=="#" and k==0:
            k+=1
        if i=="." and k!=0:
            anser+=1

K=0
if S[0]=="#":

    for i in S:

        if i=="." and K==1:
            anser+=1
        else:
            K=1

print(anser)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black =False
w_num = 0
b_num =0
for i in range(N):
    if black:
        if S[i]==".":
            w_num +=1
    
    if S[i]=="#":
        black =True
        b_num +=1
        
ans = min([w_num,b_num,N-b_num])
print(ans)

Submission status: Wrong Answer

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

flag=0
count1=0
for i in range(N):
    if(flag==1):
        if(S[i]=="."):
            count1+=1
    if(S[i]=="#"):
        flag=1
flag=0
count2=0
for s in reversed(S):
    if(flag==1):
        if(s=="#"):
            count2+=1
    if(s=="."):
        flag=1

print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
input()
S = input()


if '#' in S:
    sharp = 0
    for c in S[::-1]:
        if c == '#':
            sharp += 1
        else:
            break
    black = S.index('#')
    print(min(S[black:].count('#') - sharp, S[black:].count('.')))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
index = S.find("#")
answer = -1
if(index == -1):
    answer = 0
else:
    test = S[index:N]
    count_s = S.count("#")
    count_d = S.count(".")
    answer = min(count_s,count_d)
print(answer)

Submission status: Wrong Answer

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

m = ['#', '.']
m1 = ['#', '.', '#']
m2 = ['#', '.', '.']
m3 = ['#', '#', '.']
m4 = ['.', '#', '.']


def matching():
    count = 0
    non_count = 0
    for i in range(N):
        if S[i:i+2] != m:
            non_count += 1
            continue

        flag = True
        if i>=0 and i<= N-3:
            if S[i:i+3] == m1:
                count +=1
                S[i] = '.'
                flag = False
            elif S[i:i+3] == m2:
                count += 1
                S[i] = '.'
                flag = False
        if flag == False or i==0:
            continue


        if S[i-1:i+2] == m3:
            S[i+1] = '#'
            count += 1
        elif S[i-1:i+2] == m4:
            S[i] = '.'
            count += 1
    return count, non_count

c = 0
non = -1
while(non!=N):
    c_m, non = matching()
    c += c_m

print(c)

Submission status: Wrong Answer

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

ans = 0
cnt_black = 0
cnt_white = 0
for idx in range(n):
    if s[idx] == '#':
        cnt_black += 1
        if cnt_white >= 1:
            cnt_white = 0
    elif s[idx] == '.':
        cnt_white += 1

    if idx >= 1:
        # print(s[idx-1:idx+1], ans)
        if s[idx-1:idx+1] == '#.':
            ans += min(cnt_black, cnt_white)
            cnt_black = 0
            cnt_white = 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
siro = S.count(".")
kuro = S.count("#")
change_num = siro if siro <= kuro else kuro
print(change_num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

fb=-1
flag=0
for i in range(n):
    if flag==0 and s[i]=='#':
        fb=i
        flag+=1

if fb==(n-1):
    if fb==0:
        ans=0
    else:
        ans=1
elif fb==-1:
    ans=0
else:
    w=0
    b=1
    for i in range(fb+1,n):
        if s[i]=='.':
            w+=1
        else:
            b+=1
    ans=min(w,b)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
# . = しろ
# # = 黒
# #の横に.がないようにしたい
# #の横に.があったら#を.に変える
# or #の横に.があったら.を#に変える

# when do you replace now char to .
# 

# テストケース
"""
13
.##...#..##.#
.1 #2 .3 #1 .2 #2 .1 #1
[6 , 2 + 6 , 2 + 3 , 3 + 3 , 3 + 1 , 5 + 1 , 5 , 6]
[6 , 8 , 5 , 6 , 4 , 6 , 5 , 6]
"""
# => .....# = 2

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

def calcCount(S , N) : 
    countingChar = S[0]
    rst = []
    count = 1
    for s in S[1:] :
        if countingChar == s : 
            count += 1
        else : 
            rst.append((countingChar , count))
            count = 1
            countingChar = s
    return rst

def countRightChange(countingList) : 
    #全部を.に変えるコスト
    cnt = 0
    for elem in countingList : 
        if elem[0] == "#" : 
            cnt += elem[1]
    return cnt

def countLeftChange(countingList) : 
    # 全部を#に変えるコスト
    cnt = 0
    for elem in countingList : 
        if elem[0] == "." : 
            cnt += elem[1]
    return cnt

def calcPoint(countingList) : 
    minVal = 9999999999999
    for i in range(len(countingList)) : 
        a = countRightChange(countingList[ : i])
        b = countLeftChange(countingList[i : ])
        #print(a , b)
        if minVal > a + b : 
            minVal = a + b
    return minVal




#cnt = inorderReplace(S , N)
countingList = calcCount(S , N)
cnt2 = calcPoint(countingList)

print(cnt2)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S.find('#.') >= 0:
    print(min(S[S.find('#'):].count('.'), S[:N-1].count('#')))
else:
    print(0)

Submission status: Wrong Answer

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

#0：まだ.　1：もう#
dp = [[0, 0] for _ in range(n+1)]

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

Submission status: Wrong Answer

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

f = 0
cnt1 = 0
for s_ in s:
  if f == 1 and s_ == ".":
    cnt1 = cnt1 + 1
  if f == 0 and s_ == "#":
    f = 1

f = 0
cnt2 = 0
for s_ in (reversed(s)):
  if f == 0 and s_ == "#":
    f = 1
  if f == 1 and s_ == "#":
    cnt2 = cnt2 + 1

if len(s) == 1:
  print("0")
else:
  print(min(cnt1,cnt2))

Submission status: Wrong Answer

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

sList = list(S)

leftInd = 0
rightInd = N - 1
ind = (leftInd + rightInd) // 2

def myFunc(ind):
    
    leftNum = sList[:ind].count("#")
    rightNum = sList[ind:].count(".")

    return leftNum, rightNum


if len(set(sList)) == 1:
    ans = 0
else:
    while True:
        ind = (leftInd + rightInd) // 2
        leftNum, rightNum = myFunc(ind)
        leftNum1, rightNum1 = myFunc(ind - 1)
        leftNum2, rightNum2 = myFunc(ind + 1)
        if abs(leftNum - rightNum) <= 1:
            ans = min(leftNum + rightNum, leftNum1 + rightNum1, leftNum2 + rightNum2)
            break
        elif leftNum > rightNum:
            rightInd = ind
        else:
            leftInd = ind

print(ans)

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:
n = int(input())
s = input()
t = list(s)
a = 0
b = 0
for i in range(s.find("#"), n):
    if t[i]==".":
        a=a+1
for j in range(0, s.rfind(".")):
    if t[j]=="#":
        b=b+1     
print(min(a,b))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
def check(N, S):
    ls = []
    for i in range(N - 1):
        if S[i] == "#" and S[i + 1] == ".":
                ls.append(True)
        else:
            ls.append(False)
    return ls.count(True)

def change(N, S):
    cnts = []
    for i in range(1, N):
        form = S[:i]
        latt = S[i:]
        cnt = 0
        if form.count(".") >= form.count("#"):
            cnt += form.count("#")
        if form.count(".") < form.count("#"):
            cnt += form.count(".")
        cnt += latt.count("#")
        cnts.append(cnt)
    return cnts

if check(N, S) == 0:
    print(0)
else:
    print(min(change(N, S)))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
xx = []
ten = []
count = 0#最初
count1 = 0 
count2 = 1
count3 = 0

for i in S:
    if i=="#" and count==0:
        count1 += 1
        count = 1
    elif i =="#" and count2==1:
        count1 += 1
    elif i =="." and count2==1:
        xx.append(count1)
        count1 = 1
        count2 = 0
    elif i =="." and count2==0:
        count1 += 1
    elif i=="#" and count2==0:
        ten.append(count1)
        count1 = 1
        count2 = 1

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

for i in range(len(xx)):
    if xx[i]>=ten[i]:
        count3 += ten[i]
    else:
        count3 += xx[i]

print(count3)

Submission status: Wrong Answer

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

count = 0
s2=''

for i, wb in enumerate(s):
    print(i, wb)
    if i != (n-1):
        if wb == '#':
            s2 = s[i:]
            break

count = s2.count('.')
print(count)

Submission status: Wrong Answer

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

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

print(min(count1,count2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

SLFront = list(S)
SLRear = list(S)

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

#print(SLFront)
countF = 0
for i in reversed(range(len(SLFront)-1)):
	if SLFront[i] == "#" and SLFront[i+1] == ".":
		SLFront[i] = "."
		countF += 1
		
#print(countF,SLFront)

#print(SLRear)
countR = 0
for i in range(len(SLRear)-1):
	if SLRear[i] == "#" and SLRear[i+1] == ".":
		SLRear[i+1] = "#"
		countR += 1
		
#print(countR,SLRear)

print(min(countF,countR))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=list(input()[:-1])
c=0
for i in range(1,N):
  if S[i-1]=='#'and S[i]=='.':
    S[i]=='#'
    c+=1
print(c)

Submission status: Wrong Answer

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

i = 0
while i<len(s) and s[i] == '.':
  i+=1
j = n-1
while j>=0 and s[j] == '#':
  j-=1

s = s[i:j+1]
print(min(s.count('#'),s.count('.')))

Submission status: Wrong Answer

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

if S == ['#'] * N or S == ['.'] * N:
    print(0)
    exit()

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
  
input()
S = np.asarray(list(str(input())))
i = 0
for s in S:
 if s == "#":
  idx = i
  break
 else:
  i += 1
else:
 print(0)
 exit()
S = S[i:]
rw = S[S=="."].size
rb = S[S=="#"].size
lw = 0
lb = 0
res = 2 * 10**5

for i in range(S.size):
 if S[i] == "#":
  rb -= 1
  lb += 1
 else:
  rw -= 1
  lw += 1
 res = min(res,lb+rw)
print(res)

Submission status: Wrong Answer

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

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

if len(si)>0:
    sa=si[0]
else:
    sa=0
if len(k)>0:
    ka=k[-1]
else: ka = 0

smax = sum(si) - sa

kmax = sum(k) - ka

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

Submission status: Wrong Answer

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

count = 0

while s.count("#.") != 0:
    t = re.subn(".#.", '...', s)
    s = t[0]
    count += t[1]
    t = re.subn("##.", '###', s)
    s = t[0]
    count += t[1]
    t = re.subn("#.#", '###', s)
    s = t[0]
    count += t[1]
    t = re.subn("#..", '...', s)
    s = t[0]
    count += t[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 == '#' and tmp4 == '#':
                S[i+1] = '#'
                ans += 1
            if tmp1 == '#' and tmp4 == '.':
                S[i+1] = '#'
                ans += 1
            if tmp1 == '.' and tmp4 == '#':
                S[i] = '.'
                ans += 1
            if tmp1 == '.' and tmp4 == '.':
                S[i] = '.'
                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:
N,S = [input() for i in range(2)]
a = list(S)
c = 0
d = int(N)
for i in range(int(N)-1):
    if a[i] == "#":
        c += 1
        d -= 1
if a[int(N)-1] == "#":
    d -= 1
print(min(c,int(N)-c,d))

Submission status: Wrong Answer

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

out_num_list=[]
last_w=0
for i in range(N-1,-1,-1):
  if S[i] == '.':
    last_w = i
    break

change_num=0
for i in range(0,N-1):
  if S[i] == '#' and i < last_w:
    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())
S = input()
i = 0
while S[i] == ".":
	if i == N-1:
		break
	i += 1
c = 0
t = i
while i < N:
	if S[i] == ".":
		c += 1
	i += 1
cand1 = min(c,N-t-c)

S = S[::-1]
i = 0
while S[i] == "#":
	if i == N-1:
		break
	i += 1
c = 0
t = i
while i < N:
	if S[i] == "#":
		c += 1
	i += 1
cand2 = min(c,N-t-c)
print(min(cand1,cand2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
a = s.find('#') #左から黒
b = s.rfind('.') #右から白

ans = min([s[a:n].count('.'),s[0:b+1].count('#')])
print(ans)

Submission status: Wrong Answer

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

if s.count(".") == n:
  print(0)
  exit()

c = [0]
cc = [0]
for i in range(n):
  if s[i] == ".":
    c.append(c[-1]+1)
    cc.append(cc[-1])
  else:
    c.append(c[-1])
    cc.append(cc[-1]+1)
c = c[1:]
cc = cc[1:]

a = c.count(0)
b = cc.count(cc[-1])

if s[0] == ".":
  if s[-1] == "#":
    print(min(c[-1]-a, cc[-1]-b))
  else:
    print(min(c[-1]-a, cc[-1]))
else:
  if s[-1] == "#":
    print(min(c[-1], cc[-1]-b))
  else:
    print(min(c[-1], cc[-1]))

Submission status: Wrong Answer

Solution code:
import re
import sys
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    S = ii(str)
    return S.count("#.")


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = list(input())
    
    arr = []
    cnt = 1
    for i in range(1, n):
        if s[i] == s[i - 1]:
            cnt += 1
        else:
            arr.append(cnt)
            cnt = 1
    arr.append(cnt)
    
    if s[0] == '.':
        arr = [0] + arr
    if s[-1] == '#':
        arr += [0]
    
    for i in range(len(arr) - 3, -1, -2):
        arr[i] += arr[i + 2]
    
    ans = 0
    for i in range(0, len(arr), 2):
        if arr[i] > arr[i + 1]:
            ans += arr[i + 1]
            break
        else:
            ans += arr[i]
    
    print(ans)
    return 0

main()

Submission status: Wrong Answer

Solution code:
import sys
import re

input = sys.stdin.readline


def main():
    n = input()
    s = input().strip()
    print(sum([max([m.count("#"), m.count(".")]) for m in re.findall(r"#+\.+", s)]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def stones(s):
    k = 0
    c = s.count('#')
    for i in range(len(s)-1):
        if s[i]=='#' and s[i+1]=='.':
            s[i+1] = '#'
            k = k+1
    return min(c,k)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
numw=len([x for x in s[:-1] if x=="#"])
numb=len([x for x in s[:-1] if x=="."])
print(min(numb,numw))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [s for s in input()]
a = s.count(".")
b = 3 - a
if a >= b:
    print(a)
else:
    print(b)

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

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

print(ans)

Submission status: Wrong Answer

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

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

min_turn_stones = 2*10**5

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

print(min_turn_stones)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(input())
result = N
count = 0
result = sorted([N,a.count("#"),a.count(".")])[0]
for i in range(N):
    for j in range(i):
        if a[j] != ".":
            count += 1
    for k in range(N-i):
        if a[k] != "#":
            count += 1
    if count < result:
        result = count
print(result)

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
tw = 0
tb = 0
A = 0
for i in range(N):
    if c == 0 and S[i] == '#':
        if cw[N - 1] - cw[i] >= cb[N - 1] - cb[i] + 1:
            a += 1
        else:
            A = cw[N - 1] - cw[i]
            c = 1
            tb += 1
    elif c == 1 and S[i] == '#':
        tb += 1
    elif c == 1 or c == 2 and S[i] == '.':
        c = 2
        tw += 1
    elif c == 2:
        if tb > tw:
            a += A
            print(a)
            exit()
        else:
            c = 0
            a += tb
            tw = 0
            tb = 0
print(a + tw)

Submission status: Wrong Answer

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

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 j in range(N-1):
    if s[j]!=s[j+1]:
        s[j]=s[j+1]
        count2+=1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
for i in range(0,n) :
    if s[i] == '.' :
        c += 0
    elif s[i] == '#' :
        b = i
        break
s = s[i:n]
x = s.count('#')
y = s.count('.')
print(min(x,y))

Submission status: Wrong Answer

Solution code:
#改行入力
N = int(input())
S = input()

count = 0


for i in range(len(S)):
    if  i != len(S)-1:
        if S[i] == "#" and S[i+1] == ".":
            count = count +1

            if i == 0:
                S = "." + S[i+1:]
            elif i == len(S) - 2:
                S = S[:i+1] + '#'

            elif S[i-1] == "#":

                S = S[:i] + '#' + S[i+1:]
            elif S[i-1] == ".":
                S = S[:i-1] + "." + S[i:]

print(count)

Submission status: Wrong Answer

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

count = 0

while s.count("#.") != 0:
    t = re.subn(".#.", '...', s)
    s = t[0]
    count += t[1]
    t = re.subn("##.", '####', s)
    s = t[0]
    count += t[1]
    t = re.subn("#.#", '####', s)
    s = t[0]
    count += t[1]
    t = re.subn("#..", '...', s)
    s = t[0]
    count += t[1]
    
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = S.count(".")
if S[0] == ".":
    white_continue = True
l = 0
for s in S:
    if s == "." and white_continue:
        l += 1
    else:
        white_continue = False

count -= l
if S.count(".") == N:
    count = 0
print(count)

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)


# print(array)
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())  # 数値入力
str = list(input())  # 一文字ずつ格納
newstr = []
new1str = []

for i in range(n):
    if str[i] == "#":
        new1str = str[i:]
        break

n1 = len(new1str)
for i in range(n1):
    if new1str[n1-1-i] == ".":
        newstr = new1str[:n1-i]
        break

if len(newstr) == 0:
    print(0)
else:
    print(min(newstr.count("."), newstr.count("#")))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    S = lines.pop(0)
    # reverse
    S = S[::-1]
    # 白が現れるまで省く
    idx = S.find('.')
    S = S[idx:]

    res = 0
    while(True):
        w = S.find('#')
        b = S[w:].find('.')

        if w < 0:
            break

        if ( w < b ):
            res += w
            S = S[w+b:]
        else:
            res += min(S.count('.'), S.count('#'))
            break

    print(res)

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
onlyb = 0
onlyw = 0
twotn = 0
flag = 0
for i in range(N):
    if S[i] == ".":
        onlyb += 1
        if flag != 0:
            twotn +=1
    else:
        onlyw += 1
        flag = 1
print(min(onlyb,onlyw,twotn))

Submission status: Wrong Answer

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

change = 0
ans = 0
for i in range(a):
  if(b[i] == '#' or change == 1):
    change = 0
    if(i + 1 >= a):
      break
    else:
      if(b[i+1] == '.'):
        ans += 1
        if(i+2 < a):
          if(b[i+2] != '.'):change = 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
tmp=1
L=[]
ans=10**6
black=0
white=0
for i in range(1,len(S)):
    if S[i]==S[i-1]:
        tmp+=1
    else:
        L.append(tmp)
        tmp=1
    if i ==len(S)-1:
        L.append(tmp)

    if S[i]=='#':
        black+=1
    else:
        white+=1
cul=[0]*(len(L)+2)
for i in range(len(L)):
    cul[i+2]=L[i]+cul[i-2]


if S[0]=='.':
    for i in range(2,len(cul)):
        if i%2==0:
            ans=min(ans,cul[i-1]+white-cul[i])
        else:
            ans=min(ans,cul[i]+white-cul[i-1])
else:
    for i in range(2,len(cul)):
        if i % 2 == 0:
            ans = min(ans,cul[i]+white-cul[i-1])
        else:
            ans = min(ans,cul[i-1]+white-cul[i])


if len(L)==1:
    ans=0
else:
    ans=min(ans,sum(L[0::2]),sum(L[1::2]))

print(ans)

Submission status: Wrong Answer

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

start = -1
black = 1
white = 0

for i in range(n):
    if s[i] == "#":
        start = i
        break

if start != -1:
    for i in range(n):
        print(i)
        print(start)
        if i > start:
            if s[i] == "#":
                black+=1
            else:
                white+=1
    if black<=white:
        print(black)
    else:
        print(white)

else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = 0
b = 0
for i in range(N):
    if S[i-1] == '#':
        a += 1
    else:
        b += 1
print(min(a, b))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
#" . #
#  b=black#
#  w=white.
f=[0,1][s[0]=="#"]
g=[0,1][s[0]=="."]
b=[0]
w=[0]
#print(b,w)
for i in s:
#    print(w)
    if f==1 and i=="#":
        b[-1]+=1
    elif f==1 and i==".":
        f=0
        if w[-1]!=0: w.append(1)
        else: w[-1]=1
    elif b[-1]!=0 and f==0 and i==".":
        w[-1]+=1
    elif f==0 and i=="#":
        f=1
        if b[-1]!=0: b.append(1)
        else: b[-1]=1
x=sum(b)
y=sum(w)
if s[-1]=="#": x-=b[-1]

ans=min(x,y)
print(ans)

Submission status: Wrong Answer

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

i = 0
cnt1 = 0

if "."*n == s:
    print(0)
elif "#"*n == s:
    print(0)
else:
    for i in range(len(s)-1):
        if (s[i] == "#") and (s[i+1] == "."):
            cnt1 += 1
    print(cnt1)

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:
n=int(input())
s=list(input())
li=[]
if s[0]=='.':
  a=0
  s.insert(0,"あ")
  for i in range (0,n-1):
    if s[i+1]==s[i]:
      a=a+1
    else:
      li.append(a)
      a=1
  li.append(a)
else:
  a=1
  for i in range (0,n-1):
    if s[i+1]==s[i]:
      a=a+1
    else:
      li.append(a)
      a=1
  li.append(a)
if s[n-1]==".":
  li.append(0)
len_li=len(li)
import math
t=math.floor(len_li/2)+1
l=[]
m=0
for j in range (0,t-1):
  m=m+li[2*j+1]
x=0
y=0
for k in range (0,t):
  l.append(m+y-x)
  y=y+li[2*k]
  if k!=t-1:
    x=x+li[2*k+1]
l.sort()
print(l[0])