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()
m=S[::-1]
print(m)
c=S.count('#')
if ('.' in S) & ('#' in S):
	p=S.index('#')
	l=m.index('.')
	k=S[p::]
	a=k.count('.')
	if (p!=0)&(a==0):
		print(0)
	elif a>=c:
		 print(c-l)
	else:
		 print(a)
else:
	print(0)

Submission status: Wrong Answer

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

w_num = S.count('.')
b_num = S.count('#')

if w_num > b_num and '#.' in S:
    count = S.count('#.')
elif w_num <= b_num and '#.' in S:
    for i in range(N):
        if S_list[i] == '#' and S_list[i+1] == '.':
            count += 1
            S_list[i+1] = '#'
            S = ''.join(S_list)
        if  '#.' in S:
            dammy = 1
        else:
            break;
print(count)

Submission status: Wrong Answer

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

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

min_turn_stones = 2 * 10 ** 5
right_black_stone = 0
left_white_stone = stones.count(".")


for i in range(trial_num):
    if(stones[i] == "#"):
        right_black_stone += 1
    else:
        left_white_stone -= 1

    tmp_min = right_black_stone + left_white_stone
    if(tmp_min < min_turn_stones):
        min_turn_stones = tmp_min


print(min_turn_stones)

Submission status: Wrong Answer

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

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
            
        l.append(leftBlack + rightWhite)
        
    print(min(l))

Submission status: Wrong Answer

Solution code:
input1 = input()
input2 = input()
l_input2 = list(input2)
count = 0
tmp_count = 0
r_l_input2 = l_input2[::-1]
for i in range(0, len(r_l_input2)):
    if r_l_input2[0] == "#":
        del r_l_input2[0]
input2=("").join(r_l_input2[::-1])

if input2.count("#") >= input2.count("."):
    print(input2.count("#."))
else:
    print(input2.count("#"))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
def my_index(l, x):
        return [i for i, _x in enumerate(l) if _x == x]
if "#" in s:
    m = m = my_index(s,"#")
    if len(m) > 1:
        print(min(s[m[0] + 1:].count("."),s[m[0] + 1:].count("#"),s[m[1] + 1:].count(".") + 1))
    else:
        k = s.index("#")
        print(0 if k == n-1 else min(s[k+1:].count("."),s[k+1:].count("#") + 1))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input()) ###
    S = list(input())

    result = 10000
    for i in range(1, len(S)):
        a, b = S[:i], S[i:]
        count_sharp = a.count('#')
        count_dot = b.count('.')

        total = count_sharp + count_dot
        # print(a, b, count_sharp,count_dot, total)
        result = min(result, total)
    print(result)

main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

    if N == 1:
        print(0)
        return

    white, black = [], []
    cntw, cntb = 0, 0
    prev = S[0]
    for s in S:
        if prev != s:
            white.append(cntw)
            black.append(cntb)
            cntw, cntb = 0, 0
        if s == '.':
            cntw += 1
        else:
            cntb += 1
        prev = s
    white.append(cntw)
    black.append(cntb)

    if not sum(white) or not sum(black):
        print(0)
        return
    for i, j in enumerate(black):
        if j:
            idx = i
            break
    w = sum(white[idx:])
    b = sum(black)
    print(min(w, b))

input = lambda: stdin.readline().rstrip()
main()

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()
e = b
c = 0
d = 0
while b.count('#.') != 0 :
    c = c + b.count('#.')
    b = b.replace('#.','..')
while e.count('#.') != 0 :
    d = d + e.count('#.')
    e = e.replace('#.','##')
if c < d :
    print(c)
else :
    print(d)

Submission status: Wrong Answer

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

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

    return min(w_num, b_num)


print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
fb = -1
for i in range(N):
    if S[i] == '#':
        fb = i
        break

cnt = 0
S = S if fb == -1 else S[fb:]
for s in S:
    if s =='#':
        cnt += 1

if cnt:
    print(min(N-cnt,cnt))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
 
b=0
w=S.count(".")
 
ans=b+w
 
for s in S:
	if s == "#":
		b += 1
	else:
		w -= 1
	ans=min(ans, b+w)

Submission status: Wrong Answer

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

# the number of '#'
p0 = s.count('#')

# the number of '.'
p1 = n - p0

p_min = min(p0, p1)

wb_ = 0
bw_ = 0
for i in range(n):

    if s[i] == '.':
        bw = bw_ 
        wb = p1
    else:
        bw = bw_ + 1
        wb = p1 - 1
    
    p_min = min(p_min, (bw + wb))

print(p_min)

Submission status: Wrong Answer

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

c_b = 0
c_w = 0

# # is black and . is white
c = 0

s_c = []
for i in range(N):
    if S[i] == '#':
        c_w += 1
        if c_b > 0:
            s_c.append(['.', c_b])
            c_b = 0
    else:
        c_b += 1
        if c_w > 0:
            s_c.append(['#', c_w])
            c_w = 0


if c_w > 0:
    s_c.append(['#', c_w])
if c_b > 0:
    s_c.append(['.', c_b])

c = 0
for i in range(len(s_c)-2, -1, -1):
    if s_c[i][0] == '#':
        if s_c[i+1][0] == '.':
            if s_c[i][1] > s_c[i+1][1]:
                c += min(s_c[i][1], s_c[i+1][1])

sum_b = 0
sum_w = 0
for i in range(len(s_c)-1):
    if i == len(s_c)-1 and s_c[i][0] == '#':
        break
    if s_c[i][0] == '#':
        sum_b += s_c[i][1]
    else:
        sum_w += s_c[i][1]


print(min(sum_b, sum_w))

Submission status: Wrong Answer

Solution code:
import re

def C(N, S):
#   S = re.sub("(?<=\.)#+$", "", S)
#   S = re.sub("^\.+(?=#)", "", S)

    n_left_black = []
    sum_left_black = 0
    for c in S:
        if c == "#":
            sum_left_black += 1
        n_left_black.append(sum_left_black)

    n_right_white = []
    sum_right_white = 0
    for c in reversed(S):
        if c == ".":
            sum_right_white += 1
        n_right_white.append(sum_right_white)
    n_right_white.reverse()

#   print(n_left_black)
#   print(n_right_white)

    answer = 0
    for i, c in enumerate(S):
        if n_left_black[i] < n_right_white[i]:
            comp = "."
        elif n_left_black[i] > n_right_white[i]:
            comp = "#"
        else:
            if i < len(S)/2:
                comp = "."
            else:
                comp = "#"
#       print(comp)
        if comp != c:
            answer += 1
    print(answer)
        
#   if len(S) == 0:
#       print("0")
#   else:
#       n_white = S.count(".")
#       n_black = S.count("#")
#       print(min(n_white, n_black))

if __name__ == "__main__":
    N = int(input())
    S = input()
    C(N, S)

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)
    m = 999
    for i in range(N):
        m = min(m, S[:i].count("#") + S[i:].count("."))
    return m


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

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(S[-1] == black):
    black_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:
"""
python3 a.py < input.txt
"""
import math
import itertools as it
import heapq

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

T=[S[0]]
U=[1]
for si in S[1:]:
    if T[-1] == si:
        U[-1] = U[-1]+1
    else:
        T.append(si)
        U.append(1)

lb=None
for i in reversed(range(len(T))):
    if T[i] == "#":
        lb=i
rb=None
for i in range(len(T)):
    if T[i] == "#":
        rb=i
rw=None
for i in range(len(T)):
    if T[i] == ".":
        rw=i

if lb == None or rw == None:
    print(0)
    exit()

nb=0
for i in range(lb, len(T)):
    if T[i] == ".":
        nb = nb+U[i]
nw=0
for i in range(rw):
    if T[i] == "#":
        nw = nw+U[i]
nx=0
for i in range(lb, rb):
    if T[i] == "#":
        nx = nx+U[i]
for i in range(rw, len(T)):
    if T[i] == ".":
        nx = nx+U[i]
print(min([nb, nw, nx]))

Submission status: Wrong Answer

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

ans_ = 0
ans = 0
first = 0
for i, s in enumerate(S):
    check = -1
    if i == N-1:
        break
    if s is '#':
        ans_ += 1
        ans__ = 0
        for s_ in S[i+1:]:
            if s_ is '#':
                break
            if s_ is '.' :
                ans__ += 1
                check = 1
        if check == 1:
            if first == 0:
                ans += min(ans_, ans__)
                first = 1
            else:
                ans += max(ans_, ans__)
            ans_ = 0

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if "#" in s:
    def my_index(l, x):
        return [i for i, _x in enumerate(l) if _x == x]
    if len(my_index(s,"#")) > 1:
        m = my_index(s,"#")
        print(min(s[m[0] + 1:].count("."),s[m[0] + 1:].count("#"),s[m[1] + 1:].count(".") + 1))
    else:
        k = s.index("#")
        print(0 if k == n-1 else min(s[k+1:].count("."),s[k+1:].count("#") + 1))
else:
    print(0)

Submission status: Wrong Answer

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

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

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

print(counter)

Submission status: Wrong Answer

Solution code:
import re

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

string = s[:]

result = 0

k = 0
while True:
    # print('string', string)
    # print('result', result)
    result += len(re.findall('#\.', string))
    cnt = list()
    tmp = [string[:], string[:], string[:]]
    tmp[0] = re.sub('#\.', '.#', tmp[0])
    cnt.append((len(re.findall('#\.', tmp[0]))))
    tmp[1] = re.sub('#\.', '##', tmp[1])
    cnt.append(len(re.findall('#\.', tmp[1])))
    tmp[2] = re.sub('#\.', '..', tmp[2])
    cnt.append(len(re.findall('#\.', tmp[2])))

    # print('cnt', cnt)
    # print('tmp', tmp)
    tmpMin = min(cnt)
    id = 0
    for i in range(3):
        if cnt[i] == tmpMin:
            id = i
    # print('id', id)

    assert tmpMin == cnt[id]
    string = tmp[id]

    if len(re.findall('#\.', string)) == 0 or k == 2:
        break

    k += 1

print(result)

Submission status: Wrong Answer

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

for i in range(N+1):
    T = ["."]*i + ["#"]*(N-i)
    cnt = 0
    for j in range(N):
        if S[j] != T[j]:
            cnt += 1
    ans = min(cnt,ans)

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

s =input()

print(min(s[:s.find('###')].count('#'),s[:s.find('###')].count('.'))+min(s[s.find('###'):].count('#'),s[s.find('###'):].count('.')))

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
N = int(input())
S = input()
ind1 = 0
for i, x in enumerate(S):
    if x == '#':
        ind1 = i
        break
num = 0
for i, x in enumerate(S[::-1]):
    if x == '.':
        num = i
        break
ind2 = N - num
if ind1 >= ind2:
    print(0)
    sys.exit()
s = S[ind1:ind2]
if s[0] == '.' or s[-1] == '#' or len(s) == 0:
    print(0)
    sys.exit()
else:
    a = s.split('.')
    b = s.split('#')
    aa = []
    bb = []
    for x, y in zip(a, b):
        if len(x) != 0:
            aa.append(len(x))
        if len(y) != 0:
            bb.append(len(y))
    d = [0] + list(accumulate(aa))
    e = [0] + list(accumulate(bb))
    p = d[-1]
    ls = []
    for i in range(min(len(d), len(e))):
        ls.append(e[i]+p-d[i])
    print(min(ls))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = input()

cnt_start = False

wcnt = 0
bcnt = 0

for c in s:
    if c == '.':
        cnt_start = True
        continue

    if not cnt_start:
        continue
    else:
        bcnt += 1

cnt_start = False

for c in s:
    if c == "#":
        cnt_start = True
        continue

    if not cnt_start:
        continue
    else:
        wcnt += 1

print(min(bcnt, wcnt))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())+['A']

a=b=c=0
f=False
for i in range(len(S)-1):
    c+=1
    if ((S[i]=='#') & (S[i+1]=='.')):
        a+=c
        f=True
        c=0
    elif ((S[i]=='.') &( S[i]!=S[i+1])):
        if f==True:
            b+=c
            c=0
        else:
            f=True
            c=0
if a>b:
    print(b)
else : print(a)

Submission status: Wrong Answer

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

cntA = 0
for i in S:
    if i == '.':
        cntA += 1
    else:
        break

cntB = 0
newS = ''.join(list(reversed(S)))
for i in newS:
    if i == '#':
        cntB += 1
    else:
        break
if S.count('.') == N:
    ANS1 = 0
else:
    ANS1 = S[cntA:N-cntB].count('.') 
if S.count('#') == N:
    ANS2 = 0
else:
    ANS2 = S[cntA:N-cntB].count('#')
#print(S[cntA:N-cntB])
print(min(ANS1, ANS2))

Submission status: Wrong Answer

Solution code:

n=int(input())
s=str(input())
"""
n = 8
s = ".#####.#"
print(s)
print(len(s))
"""
memo = []
countwb=0
now = s[0]
count = 0
if now == "#":
    memo.append(0)
while(count<n):
    if s[count]==now:
        countwb+=1
    else:
        memo.append(countwb)
        countwb = 1
        now = s[count]
    count+=1
memo.append(countwb)
#print(memo)
#print(memo[len(memo)-3])


count_b = []
c_b = 0
for  i in range(1,len(memo),2):
        c_b += memo[i]
        count_b.append(c_b)
#print(count_b)

count_w = []
c_w = 0
for  i in range(0,len(memo),2):
        c_w += memo[i]
        count_w.append(c_w)
#print(count_w)

#白白．．．黒黒にする
w_b = 0
if len(memo)%2==1:
    #最後が白
    w_b += memo[-1]
    if len(count_b)>1:
        w_b += count_b[-2]
else:
    #最後が黒
    if len(count_b)>1:
        if count_w!=[]:
            w_b += min(count_b[-2],memo[-2])
        else:
            w_b += count_b[-2]
#print("w_b",w_b)
#全部白にする
allw = 0
if count_b!=[]:
    allw = count_b[-1]
#print("allw",allw)
#全部黒にする
allb = 0
if count_w!=[]:
    allb = count_w[-1]
#print("allb",allb)

print(min(w_b,allb,allw))

Submission status: Wrong Answer

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

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

T=[S[0]]
U=[1]
for si in S[1:]:
    if T[-1] == si:
        U[-1] = U[-1]+1
    else:
        T.append(si)
        U.append(1)

lb=None
for i in reversed(range(len(T))):
    if T[i] == "#":
        lb=i
rb=None
for i in range(len(T)):
    if T[i] == "#":
        rb=i
rw=None
for i in range(len(T)):
    if T[i] == ".":
        rw=i

if lb == None or rw == None:
    print(0)
    exit()

nb=0
for i in range(lb, len(T)):
    if T[i] == ".":
        nb = nb+U[i]
nw=0
for i in range(rw):
    if T[i] == "#":
        nw = nw+U[i]
nx=0
for i in range(lb, rb):
    if T[i] == "#":
        nx = nb+U[i]
for i in range(rw, len(T)):
    if T[i] == ".":
        nx = nx+U[i]
print(min([nb, nw, nx]))

Submission status: Wrong Answer

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

ans1 = 0
for i in range(N):
    if S[i] == '#':
        ans1 = S[i:].count('.')
        break

ans2 = 0
S2 = S[::-1]
for i in range(N):
    if S2[i] == '.':
        ans2 = S2[i:].count('#')
        break

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

print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

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

N = input()
S = input()



ans = 0;

for k,v in enumerate(S):
    if 0 <= k < len(S)-1:
        
        if v == '#' and S[k-1]:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
###
#main
if __name__ == "__main__":
    N = int(input())
    S = input()
#    count = 0
    countMin = 200001
    counttemp = 0
    isWhite = True
    numlist = []
    for t in S:
        if t == "#" and isWhite:
            isWhite = False
            numlist.append(counttemp)
            counttemp = 0
        if t == "." and not isWhite:
            isWhite = True
            numlist.append(counttemp)
            counttemp = 0
        counttemp += 1
    
    numlist.append(counttemp)
    if len(numlist) <= 2:
        countMin = 0
    else:
        countMin = sum(numlist[2::2])
        temp = countMin
        i = 2
        while i < len(numlist):
            countMin += numlist[i-1] - numlist[i] if numlist[i-1] < numlist[i] else 0
            i += 2
#    print(numlist)           
    print(countMin)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
s_list = list(s)
nmone = int(n) - 1
changednum = 0
global nextchecknum
nextchecknum = 0
for num in range(nmone):
  nump = num + 1
  if nextchecknum >= nump:
    if s_list[num] == "#" and s_list[nextchecknum] == ".":
      s_list[nump] = "#"
      changednum += 1
      nextchecknum += 1
    else:
      pass
  else:
    if s_list[num] == "#" and s_list[nump] == ".":
      s_list[nump] = "#"
      changednum += 1
      nextchecknum = nump + 1
    else:
      pass
#sed = "".join(s_list)
print(changednum)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
z = 0
if len(s) > 1:
    for i in range(0,len(s)-1):
        if s[i] == "#" and s[i+1] == ".":
            z += 1
print(z)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
re_S = S[::-1]

x = 0
y = 0
for i in range(N):
    if S[i] == '#':
        x += S[i+1:].count('.')
        break       
    else:
        continue

for i in range(N):
    if re_S[i] == '.':
        y += re_S[i+1:].count('#')
        break       
    else:
        continue
 
print(min(x, y))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if all([v == '.' for v in s]):
    print(0)
else:
    r = 0
    s = s[s.find('#'):]
    while (True):
        k = s.find('.#') + 1
        if k == 0:
            a = s.find('.')
            b = len(s) - a
            r += min(a, b)
            break
        else:
            t = s[:k]
            a = t.find('.')
            b = len(t) - a
            r += min(a, b)
            s = s[k:]
    print(r)

Submission status: Wrong Answer

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

tmp = S[0]
count = 0

Blist = []
Wlist = []

for i in range(N):
    if S[i] == tmp:
        count += 1
    else:
        if tmp == '#':
            Blist.append(count)
        else:
            Wlist.append(count)
        count = 1
        tmp = S[i]

if S[-1] == '#':
    Blist.append(count)
else:
    Wlist.append(count)

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

if S[-1] == '#':
    Blist = Blist[:-1]

counter = []

ruiB = [0]
ruiW = [sum(Wlist)]

for i in range(len(Blist)):
    ruiB.append(Blist[i] + ruiB[-1])
    ruiW.append(ruiW[-1] - Wlist[i])


if len(Wlist) == 0:
    print(0)
elif len(Wlist) == 1:
    print(min(Wlist[0], N-Wlist[0]))
else:
    for i in range(len(ruiB)):
        counter.append(ruiB[i] + ruiW[i])
        print(min(counter))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input() + '#'
 
flag = 0
b = 0
w = 0
ans = 0
ans2 = 0
for s in S:
    if s == '#':
        if flag == 2:
            ans += b
            ans2 += w
            b = 1
            w = 0
            flag = 1
        else:
            b += 1
            flag = 1
    else:
        if flag == 1:
            w += 1
            flag = 2
        elif flag == 2:
            w += 1
        
print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
s_list = list(s)
nmone = int(n) - 1
changednum = 0
global nextchecknum
nextchecknum = 0
for num in range(nmone):
  nump = num + 1
  if nextchecknum >= nump:
    if s_list[num] == "#" and s_list[nextchecknum] == ".":
      s_list[nump] = "#"
      changednum += 1
      nextchecknum += 1
      print(nextchecknum)
    else:
      pass
  else:
    if s_list[num] == "#" and s_list[nump] == ".":
      s_list[nump] = "#"
      changednum += 1
      nextchecknum = nump + 1
    else:
      pass
#sed = "".join(s_list)
print(changednum)

Submission status: Wrong Answer

Solution code:

from itertools import groupby
N = int(input())
S = input()
b = 0
w = 0
x = ""
for k, v in groupby(S):
  if not x:
    if k == ".":
      continue
  v = len(list(v))
  if k == "#":
    b += v
  else:
    w += v
  x += k
if x:
  if x[-1] == "#":
    b -= v
print(min(b,w))

Submission status: Wrong Answer

Solution code:
n = int(input())
s =  list(input())
ans = 0
if s[0] == "#":
    for i in range(n-1):
        if s[i] == "#" and s[i+1] == ".":
            s[i+1] = "#"
            ans += 1
else:
    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:
n = int(input())
s = list(input())

start = -1
black = 1
white = 0
start2 = -1
black2 = 0
white2 = 1

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

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

for i in range(n):
    if s[n-i-1] == ".":
        start2 = n-i
        break

if start != -1:
    for i in range(n):
        if n-i < start2:
            if s[i] == "#":
                black2+=1
            else:
                white2+=1

if start == -1 or start2 == -1:
    print(0)
else:
    if black < white and black < black2 and black < white2:
        print(black)
    elif white < black and white < black2 and white <white2:
        print(white)
    elif black2 < black and black2 < white and black2 < white2:
        print(black2)
    else:
        print(white2)

Submission status: Wrong Answer

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#S=input()
#import fractions
#lis=list(map(int,input().split()))

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

count=0 #black
flag=-1 #first black
for i in range(n):
    if s[i]=="#" and flag==-1:
        flag=i
        break
a="."*flag+"#"*(n-flag)
b="."*n
c="#"*n
aa,bb,cc=0,0,0
for i in range(n):
    if a[i]!=s[i]:
        aa+=1
for i in range(n):
    if b[i]!=s[i]:
        bb+=1
for i in range(n):
    if c[i]!=s[i]:
        cc+=1

ans=min(aa,bb,cc)

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i]=='#':
        break
B = S[i:].count('#')
W = S[i:].count('.') - len(S[i:].split('#')[0])
if S[-1]=="#":
    B -= 1
ans = min(B,W+1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
replace_point = -1
while 0 == 0:
    replace_point = S.find("#.")
    right_replace_point = replace_point
    r_replace_point = replace_point
    if replace_point == -1:
        break
    left_rep = 1
    right_rep = 1
    if replace_point != 0:
        while 1 == 1:
        # 左を見に行く
            if S[replace_point-1:replace_point] == "#":
                left_rep += 1
                replace_point -= 1
            else:
                break
    if right_replace_point != len(S):
        while 1 == 1:
        # 右を見に行く
            if S[right_replace_point+2:right_replace_point+3] == ".":
                right_rep += 1
                right_replace_point += 1
            else:
                break
    ans += min(left_rep, right_rep)
    S = S[r_replace_point+2:]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = long(sys.stdin.readline())
    S = sys.stdin.readline().lstrip('.').rstrip('#')
    print(S)
    numA = S.count('.')
    numB = S.count('#')
    if numA == numB:
        print(numA - 1)
    else:
        print(min(numA, numB))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

S += "q"

L = []
cnt = 0
for i in range(N) :
    cnt += 1
    if S[i] != S[i+1] :
        L.append(cnt)
        cnt = 0

A = []
B = []

for i in range(len(L)) :
    if i % 2 == 0 :
        A.append(L[i])
    else :
        B.append(L[i])

if len(L) == 1 :
    ans = 0
elif len(L) == 2 :
    if S[0] == "#" :
        ans = min(L)
    else :
        ans = 0
elif len(L) == 3 :
    if S[0] == "#" :
        ans = min(L[0],L[1])
    else :
        ans =min(L[2],L[1])
else :
    if S[0] == "#" :
        if len(L) % 2 == 0 :
            a = min(A.pop(-1), B.pop(-1))
            b = min(sum(A),sum(B))
            ans = a+b
        else :
            A.pop(-1)
            a = min(A.pop(-1), B.pop(-1))
            b = min(sum(A),sum(B))
            ans = a+b
    else :
        if len(L) % 2 == 0 :
            B.pop(-1)
            A.pop(0)
            if len(L) == 4 :
                ans = min(A[0],B[0])
            else :
                a = min(A.pop(-1),B.pop(-1))
                b = min(sum(A),sum(B))
                ans = a+b
        else :
            A.pop(0)
            a = min(A.pop(-1),B.pop(-1))
            b = min(sum(A),sum(B))
            ans = a+b
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
 
if s.count('.') == len(s):
    print(0)
elif s.count('#') == len(s):
    print(0)
else:
    s_ = s
    for i, wb in enumerate(s_):
        if wb == '.':
            s_ = s[i+1:]
        else:
            break
    
    ans_black_change = s_.count('#')
    if s[-1] == '#':
        for black in s[::-1]:
            if black == '#':
                ans_black_change -= 1
            else:
                break
    ans_white_change = s_.count('.')
    
    ans = min(ans_black_change, ans_white_change)
    print(ans)

Submission status: Wrong Answer

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


def m():
    ans = 0
    left, right = 0, N
    black = 0
    white = 0
    tmp = '#'
    for i in range(N):
        if S[i] == '#':
            left = i
            break
    new_s = S[left:]
    prev = '#'
    for c in new_s:
        if c == '#' and prev == '#':
            black += 1
            prev = c
            continue

        if c == '.' and prev == '.':
            white += 1
            prev = c
            continue

        if c == '#' and prev == '.':
            white += 1
            prev = c
            continue

        if c == '.' and prev == '#':
            ans += min(black, white)
            black = 1
            white = 0
            prev = c
            continue
    ans += min(black, white)
    return ans

print(m())

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = n
for i in range(n):
    c = s[i:].count('.') + s[:i].count('#')
    r = min(r, c)
print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
start = s[0]
pattern = []

prev = ''
b = 0
w = 0
for i in s:
    if (i == '#' and prev == '#') or (i == '#' and prev ==''):
        b += 1
    elif (i == '.' and prev == '.') or (i == '.' and prev == ''):
        w += 1
    elif i == '#':
        b += 1
        pattern.append(w)
        w = 0
    else:
        w += 1
        pattern.append(b)
        b = 0
    prev = i
    
if prev == '#':
    pattern.append(b)
else:
    pattern.append(w)

totalb = 0
totalw = 0
for i in range(len(pattern)):
    if start == '.':
        if i % 2 == 0:
            totalw += pattern[i]
        else:
            totalb += pattern[i]
    else:
        if i % 2 == 0:
            totalb += pattern[i]
        else:
            totalw += pattern[i]
        
if len(pattern) == 1 or (len(pattern) == 2 and start == '.'):
    print(0)
else:
    if start == '.':
        print(min(totalw - pattern[0], totalb))
    else:
        print(min(totalw, totalb))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input())
b=a.copy()
c=a.copy()

sum=0
sum2=0

for i in range(1,n):
  if (a[-i] == "." and a[-i-1] == "#"):
    a[-i-1] = "."
    sum += 1
    
for i in range(1,n-1):
  if (c[-i] == "#" and c[-i-1] == "." and c[-i-2] == "#"):
    c[-(i+1)] = "#"
    sum2 += 1
  elif (c[-i] == "." and c[-i-1] == "#"):
    c[-(i+1)] = "."
    sum2 += 1
    
print(min([b.count("."),b.count("#"),sum,sum2]))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
print(min(s.count('.'),s.count('#'))-(1 if s[0]=='.' or s[n-1]=='#' else 0))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

intLength = int(input())
strStones = input()

intCount = 0
strPre = ""
# 黒(#)の右に白(.)がある場合に変更
for intIdx in range(intLength):
    if strPre == "#" and strStones[intIdx] == ".":
        intCount += 1
    strPre = strStones[intIdx]

print(intCount)