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()
b,w,ans=0,0,10**5+1
for i in range(N):
	b=S[0:i].count('#')
	w=S[i::].count('.')
	ans=min(b+w,ans)
print(ans)

Submission status: Wrong Answer

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

print(cou)

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:
n = int(input())
s = input()

first_flag = False
second_flag = False
tmp_w = 0
tmp_b = 0
k = 0

for i, c in enumerate(s):
    if c == "#":
        if second_flag:
            if tmp_b > tmp_w:
                k += tmp_w
            else:
                k += tmp_b
            tmp_b = 0
            tmp_w = 0
            second_flag = False
        tmp_b += 1
        first_flag = True
    else:
        if first_flag:
            tmp_w += 1
            second_flag = True

    if i == len(s) - 1:
        if second_flag:
            if tmp_b > tmp_w:
                k += tmp_w
            else:
                k += tmp_b

print(k)

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, S):

    ans = 0
    l = len(S)
    prev = S[l-1]
    for i in xrange(len(S)-1):
        if S[l-i-2] == "#" and prev == ".":
            ans += 1
        prev = S[l-i-2]
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    ans = solve(int(N), S)
    print ans

Submission status: Wrong Answer

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

b=0
w=s.count(".")
ans = n
for i in range(n):
    if w==0 :
        break
    if s[i]!=s[i-1] and i>0:
        ans=min(ans,b+w)
    if s[i]=="#":
        b=b+1
    if s[i]==".":
        w=w-1
    
print(min(ans,b+w))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c = 0
A = int(S.count("."))
B = N - A
if len(S) == N:
    if 1 <= N <= 2 * 10 ** 5:
        if "." in S:
            if "#" in S:
                S.replace(".#","ee")
                D = S.find("e") + 1
                C = N - D + 1                
                print(N - C + B)
            else:
                print(0)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
lis = []
ws=s.count('.')
lis.append(ws)
bs = 0
for x in s:
    if x == '#':
        bs += 1
        lis.append(bs+ws)
    else:
        ws -= 1
lis.append(bs+ws)
print(min(lis))

Submission status: Wrong Answer

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

a = S.count('.')
r = a

for i in range(N):
    if S[0] == '#':
        a += 1
    else:
        a -= 1
    r = min(r, a)

print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
if N == 1:
    print(0)
    exit()
elif N == 2 and (S[0] == '.' and S[1] == '#'):
    print(0)
    exit()
else:
    S = S[0] + S + S[N - 1]
    S = list(S)
    for n in range(N):
        if S[n] == '.' and S[n + 2] == '.' and S[n + 1] == '#':
            ans += 1
            S[n + 1] = '.'
        elif S[n] == '#' and S[n + 2] == '#' and S[n + 1] == '.':
            ans += 1
            S[n + 1] = '#'
print(ans)

Submission status: Wrong Answer

Solution code:
def main(word):
    strs = list(word)
    reversed_strs = list(reversed(strs))

    last_del_num = 0
    for i, s in enumerate(reversed_strs):
        if s == ".":
            break
        if s == "#":
            last_del_num += 1

    # if len(reversed_strs) > 1:
    del(reversed_strs[0:last_del_num])

    b_count = reversed_strs.count("#")
    w_count = reversed_strs.count(".")

    if b_count == 0:
        return 0

    if w_count == 0:
        return 0

    if b_count < w_count:
        return b_count

    return w_count


if __name__ == "__main__":
    input()
    word = input()
    print(main(word))

Submission status: Wrong Answer

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

li = list(S)
count = 2 * 10 ** 5
black = 0

for i in range(N):
    if '#' == S[i]:
        black += 1
    white = S[i+1:].count('.')
    count = min(count, black+white)
print(count)

Submission status: Wrong Answer

Solution code:
import re

n = int(input())
s = input()
left = 0
right = len(re.findall('\.', s))

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

print(cnt)

Submission status: Wrong Answer

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

a = S.count('.')
r = a

for i in range(N):
    if S[0] == '#':
        a += 1
    else:
        a -= 1
    a = min(r, a)

print(a)

Submission status: Wrong Answer

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

#.#
b = S.count("#")
w = S.count(".")

cotB = 0
cotW = 0
ans = 100000
for i,s in enumerate(S):
    if s ==".":
        cotW+= 1
    else:
        cotB+=1
    if ans >=  cotB + (w - cotW):
        ans = cotB + (w - cotW)
print(ans)

Submission status: Wrong Answer

Solution code:
def chec(s):
    llis = []
    rlis = []
    clis = 0
    lef = 0
    rig = 0
    rtmp = 0
    ltmp = 0
    flg = 0
    na = len(s)
    for i in reversed(range(0,na-1)):
        if i != na and s[i] == '#' and s[i+1] == '.' :
            #clis+= 1
            #print(i)
            rtmp = i+1
            ltmp = i
            while ltmp != -1 and s[ltmp] == '#':
                lef += 1
                ltmp -= 1
            llis.append(lef)
            while rtmp+1 != na and s[rtmp] == '.':
                rig += 1
                rtmp += 1
            rlis.append(rig)
            lef = 1
            rig = 1
            rtmp = 0
            ltmp = 0

    #print(llis)
    #print(rlis)
    clis = min(sum(llis),sum(rlis))
    return clis


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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
t=0
x=[0]*N
while t<N:
    x[t]=[]
    k=0
    while k<N:
        if k<t:
            x[t].append('.')
        else:
            x[t].append('#')
        k=k+1
    t=t+1
l=0
counter=N
while l<N:
    list=x[l]
    r=0
    while r<N:
        cc=0
        if list[r]!=S[r]:
            cc=cc+1
        r=r+1
    if cc<counter:
        counter=cc
    l=l+1
m=0
ccc=0
while m<N:
    if S[m]!='.':
        ccc=ccc+1
    m=m+1
print(min(counter,ccc))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cou = 0
for i in range(1, n):
    if s[i-1] == '#':
        if not s[i-1] == s[i]:
            cou += 1

print(cou)

Submission status: Wrong Answer

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

ans = n

for i in range(n):
	tmp=0
	tmp_w=s[0:i]
	tmp_b=s[i:n]
	tmp += tmp_w.count("#")
	tmp += tmp_b.count(".")
	tmp_ans=0
	ans = ans if ans <=tmp_ans else tmp_ans
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
list_S = list(S)
N1 = 0
X = list_S.count('.')

if N == X:
    print('0')
else:
    for N in list_S:
        if list_S[N1] == '.':
            N1 += 1
        else:
            list_SS = list_S[N1:]
            X1 = list_SS.count('.')
            print(X1)
            break

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:
def chec(s):
    llis = []
    rlis = []
    clis = 0
    lef = 0
    rig = 0
    rtmp = 0
    ltmp = 0
    flg = 0
    na = len(s)
    for i in reversed(range(0,na-1)):
        if i != na and s[i] == '#' and s[i+1] == '.' :
            #clis+= 1
            #print(i)
            rtmp = i+1
            ltmp = i
            while ltmp != -1 and s[ltmp] == '#':
                lef += 1
                ltmp -= 1
            llis.append(lef)
            while rtmp+1 != na and s[rtmp] == '.':
                rig += 1
                rtmp += 1
            rlis.append(rig)
            lef = 1
            rig = 1
            rtmp = 0
            ltmp = 0

    print(llis)
    print(rlis)
    clis = min(sum(llis),sum(rlis))
    return clis


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

Submission status: Wrong Answer

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

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

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

s = s[count_d:n-count_s]
sharp_num = s.count('#')
dot_num = s.count('.')
print(min(sharp_num,dot_num))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = []
R = s.count("#")
L = 0
check = 0 # 直前が黒だったか

for i in s:
    if i == "#":
        R -= 1
        if check == 0:
            check = 1
            ans.append(R+L) # R+Lが答えの候補
        elif check == 1:
            L += 1
            ans.append(R+L)
    elif i == ".":
        if check == 0: # 一つ前が白のとき
            ans.append(R+L)
        elif check == 1: # 一つ前がWのとき
            check = 0
            L += 1
            ans.append(R+L)

print(min(ans))

Submission status: Wrong Answer

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

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

if w == 0 or b == 0:
    print(0)
    exit()

ans = 10 ** 6
nw = w
nb = 0
for i in range(N):
    if S[i] == '.':
        nb += 1
        nw -= 1
    else:
        nb -= 1
        nw += 1
    ans = min(ans, nb + nw)

print(ans)

Submission status: Wrong Answer

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

a = S.count('.')
r = a

for i in range(N):
    if S[0] == '#':
        a += 1
    else:
        r -= 1
    a = min(r, a)

print(a)

Submission status: Wrong Answer

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


def count_black(wb):
    return wb.count('#')


def count_white(wb):
    return wb.count('.')


min_count = n
for i in range(1, n):
    if s[i-1] != s[i]:
        count = count_black(s[:i]) + count_white(s[i:])
        if min_count > count:
            min_count = count

print(min_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input() + 'a'

counts = [s.count('.'), s.count('#')]
for i, stone in enumerate(s):
  if stone == '.' and s[i+1] == '#':
    counts.append(s[:i].count('#') + s[i:].count('.'))
    
print(min(counts))

Submission status: Wrong Answer

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

s=input()

ans = n

for i in range(n):
	tmp=0
	tmp_w=s[0:i]
	tmp_b=s[i:n]
	tmp += tmp_w.count("#")
	tmp += tmp_b.count(".")
	tmp_ans=0
	ans =min([ans,tmp_ans])
print(ans)

Submission status: Wrong Answer

Solution code:
# reffer https://atcoder.jp/contests/tenka1-2019-beginner/submissions/5060831
N = int(input())
S = [1 if x == '.'  else 0 for x in list(input())]

cost = sum(S)
min_cost = cost
print(min_cost)

for i in range(N):
    if S[i] == 0:
        cost += 1
    else:
        cost -= 1

    print(cost)
    if min_cost > cost:
        min_cost = cost

print(min_cost)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
print(min(s.count('.'),s.count('#')))

Submission status: Wrong Answer

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

answer = 200000
b = 0
w = s.count(".")
for i in range(len(s)):
    if s[i] == "#":
        b += 1
    else:
        w -= 1
    answer = min(answer, b+w)

print(answer)

Submission status: Wrong Answer

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

s = s.rstrip('#')
s = s.lstrip('.')

if len(set(s)) <= 1:
    print(0)
    exit(0)

print(min(s.count('#'), s.count('.')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
count = 0
lst = []
for i,char in enumerate(S):
  if (char == "."):
    lst.append(i)

min = 0   
length = len(lst)
if (length == 0):
  print(min)
elif(length == 1):
  if (lst[0] == 0):
    print(min)
  else:
    min = 1
    print(min)
else:
  for idx, i in enumerate(lst):
    if (idx == 0):
      if (lst[0] >= 1):
        count += lst[0]
    else:
      count += lst[idx] - lst[idx-1] -1 
  if (count > length):
    min = length
  else:
    min = count
  print(min)

Submission status: Wrong Answer

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

ans = n
cnt_w = s.count('.')
cnt_k = 0
if cnt_w == n or cnt_w == 0:
    ans = 0
    print(ans)
else:
    for i in range(n):
        if s[i] == '.':
            cnt_w -= 1
        else:
            cnt_k += 1
        if ans > cnt_w + cnt_k:
            ans = cnt_w + cnt_k
    print(ans)

Submission status: Wrong Answer

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

ans = N
for i in range(N):
  ans = min(ans, S[i:].count('.')+S[:i].count('#'))
  
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

x = int(input());
s = list(input());

z = copy.copy(s);

j = 0;
p = 0;

for i in range(x):
    if str(s[i]) == '#':
        if i != x-1:
         if str(s[i+1]) == '.':
              j = j + 1;


for i in(range(x)):
    if str(z[i]) == '#':
        if i != 0:
         if str(z[i-1]) == '.':
              p = p + 1;

print(min(j,p));

Submission status: Wrong Answer

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

def calc():
    min_cost = n
    left_cost = s.count('#')
    right_cost = s.count('.')

    return(min(left_cost, right_cost))

print(calc())

Submission status: Wrong Answer

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

b=0
w=s.count(".")
ans = n
for i in range(n):
    if s[i]!=s[i-1] and i>0:
        ans=min(ans,b+w)
    if s[i]=="#":
        b=b+1
    if s[i]==".":
        w=w-1
    
print(min(ans,b+w))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
S = list(input())

white_count=0
black_count=0
white_acc_list=[]
black_acc_list=[]
for i in range(N):
    if(S[i]=="."):
        white_count+=1
    else:
        black_count+=1
    black_acc_list.append(black_count)
    white_acc_list.append(white_count)

v = []
for i in range(N):
    v.append(black_acc_list[i]+(white_acc_list[N-1]-white_acc_list[i]))

#print(v)
print(np.min(v))

Submission status: Wrong Answer

Solution code:
def pro():
    _, s = input(), [s for s in input()]
    if "#" not in s:
        return print(0)
    elif "." not in s:
        return print(0)

    s = s[s.index("#"):]

    back = 0
    for i in range(1, len(s)+1):
        if s[-i] == "#":
            back += 1
        else:
            break
            
    s = s[:-back]
    a = s.count(".")
    b = len(s) - a

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

pro()

Submission status: Wrong Answer

Solution code:
def main(word):
    strs = list(word)
    reversed_strs = list(reversed(strs))
    # strs.reverse()
    # print(reversed_strs)

    last_del_num = 0
    for i, s in enumerate(reversed_strs):
        if s == ".":
            break
        if s == "#":
            last_del_num += 1

    del(reversed_strs[0:last_del_num])

    # print(reversed_strs)

    b_count = reversed_strs.count("#")
    w_count = reversed_strs.count(".")

    if b_count == 0:
        return 0

    if w_count == 0:
        return 0

    if b_count < w_count:
        return b_count

    return w_count


if __name__ == "__main__":
    input()
    word = input()
    print(main(word))

    # count = 0
    # iRegular = False
    # for i, _ in enumerate(strs):
    #     if i == 0:
    #         continue
    #     if strs[i-1] == "#" and strs[i] == ".":
    #         count += 1
    #         continue

    #     if i < 2:
    #         continue
    #     if iRegular and strs == ".":
    #         count += 1
    #         continue
    #     else:
    #         iRegular = False
    #     if strs[i-2] == "#" and strs[i-1] == "." and strs[i] == ".":
    #         iRegular = True
    #         count += 1

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
 
check_black_stone = False
check_white_stone = False
change_counter_typeA = 0
change_counter_typeB = 0
 
 
for stone_color in S:
    if check_black_stone and stone_color == ".":
        change_counter_typeA += 1
    elif stone_color == "#":
        check_black_stone = True
 
for stone_color in S[::-1]:
    if check_white_stone and stone_color == "#":
        change_counter_typeB += 1
    elif stone_color == ".":
        check_white_stone = True
 
result = change_counter_typeA if change_counter_typeA < change_counter_typeB else change_counter_typeB
print(result)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import re

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

min = n

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=float("inf")
for i in range(n):
  a=s[:i].count("#")+s[i:].count(".")
  ans=min(ans,a)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
m=S[::-1]
c=S.count('#')
if ('.' in S) & ('#' in S):
	p=S.index('#')
	l=m.index('.')
	k=S[p::]
	a=k.count('.')
	if a==0:
		print(0)
	elif a>=c-l:
		 print(c-l)
	else:
		 print(a)
else:
	print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
"""
x=n
flag1=False
flag2=False
for i in range(n):
    if s[i]=="#" and flag1==False:
        x=i
        flag1=True
    if s[n-1-i]!="#" and flag2==False:
        y=n-i
        flag2=True
    if flag1==True and flag2==True:
        break

S=s[x:y]

b=S.count("#") 
w=len(S)-b
cb=0
cw=0
for i in range(len(0,S-1))[::-1]:

    if S[i]==".":
        cw=cw+1
    if S[i]=="#":
        cb==cw+1
    if S[i]!=S[i-1]:
        cb>cw
"""
b=0
w=s.count(".")
ans = n
for i in range(n):
    if s[i]!=s[i-1] and i>0:
        ans=min(ans,b+w)
    if s[i]=="#":
        b=b+1
    if s[i]==".":
        w=w-1
    
print(min(ans,b+w))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def chec(s):
    llis = []
    rlis = []
    clis = 0
    lef = 0
    rig = 0
    rtmp = 0
    ltmp = 0
    flg = 0
    na = len(s)
    for i in reversed(range(0,na-1)):
        if i != na and s[i] == '#' and s[i+1] == '.' :
            #clis+= 1
            #print(i)
            rtmp = i+1
            ltmp = i
            while ltmp != 0 and s[ltmp] == '#':
                lef += 1
                ltmp -= 1
            llis.append(lef)
            while rtmp+1 != na and s[rtmp] == '.':
                rig += 1
                rtmp += 1
            rlis.append(rig)
            lef = 1
            rig = 1
            rtmp = 0
            ltmp = 0

    #print(llis)
    #print(rlis)
    clis = min(sum(llis),sum(rlis))
    return clis


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

Submission status: Wrong Answer

Solution code:
import copy

x = int(input());
s = list(input());

z = copy.copy(s);

j = 0;
p = 0;

for i in range(x):
    if str(s[i]) == '#':
        if i != x-1:
         if str(s[i+1]) == '.':
              s[i+1] = '#';
              j = j + 1;


for i in reversed(range(x)):
    if str(z[i]) == '#':
        if i != x-1:
         if str(z[i+1]) == '.':
              z[i] = '.';
              p = p + 1;

print(min(j,p));

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:
    print(min(totalw, totalb))

Submission status: Wrong Answer

Solution code:

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


"""
#.#.#.#

#があるときそれより右に.があってはいけない
 #よりもみぎにある.を全部#に帰る
 #より右に.があるような#を全て.に帰る
 のどちらか
"""
if("." not in S):
	print(0)
	exit()
if("#" not in S):
	print(0)
	exit()
first_black=S.find("#")
last_white=S.rfind(".")
# 黒より右に白がないなら良い
if("." not in S[first_black:]):
	print(0)
	exit()
#最初の黒よりも右側の白を全部黒にする vs 最後の白よりも左の黒を全部白に
print(min(S[first_black:].count("."),S[:last_white].count("#")))

Submission status: Wrong Answer

Solution code:


n = int(input())
s = list(input())
a = list(map(lambda x:x, s))
def stones(s):
    k = 0
    for i in range(len(s)-1):
        if s[i]=='#' and s[i+1]=='.':
            s[i+1] = '#'
            k = k+1
    return k

def stone(a):
    k = 0
    c = list(reversed(a))
    for w in range(len(c)-1):
        if c[w]=='.' and c[w+1]=='#':
            c[w+1] = '.'
            k = k+1
    return k
print(min(stones(s),stone(a)))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
M=S.count('.')
ans=M

for i in range(N):
	if S[i] == '#':
		M = M+1
	else:
		M = M-1
print(min(M,ans))

Submission status: Wrong Answer

Solution code:

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

ans = n
cnt_w = s.count('.')
cnt_k = 0
if cnt_w == n or cnt_w == 0:
    ans = 0
    print(ans)
else:
    for i in range(n):
        if s[i] == '.':
            cnt_w -= 1
        else:
            cnt_k += 1
        if ans > cnt_w + cnt_k:
            ans = cnt_w + cnt_k
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline())
s = sys.stdin.readline()

bcnt = 0
ans = 0
for t in s:
    if t == '#':
        bcnt += 1
    else:
        if bcnt > 0:
            ans += 1
            bcnt -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate


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

black = [0 for _ in range(N)]
white = [0 for _ in range(N)]

for i, s in enumerate(S):
    if s == '#':
        black[i] = 1
    else:
        white[i] = 1

# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]

ans = []
for i in range(N):
    ans.append(black[i] + white[i])

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
m = n
for i in range(n):
    if m > s[:i].count("#") + s[i:].count("."):
        m = s[:i].count("#") + s[i:].count(".")
        
print(m)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c=0
d=0
switch=0
for i in range(N):
    if S[i]=='#' and switch==0:
        switch=1
    elif switch==1 and S[i]=='.':
        c=S[i-1:].count('.')
        break
S=S[::-1]
switch=0
for i in range(N):    
    if S[i]=='.' and switch==0:
        switch=1
    elif S[i]=='#' and switch==1:
        d=S[i-1:].count('#')
        break


print(min(c,d))

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(S)
#   print(n_left_black)
#   print(n_right_white)

    answer = 0
    rev_flag = False
    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 = "#"
            rev_flag = True
        else:
            if rev_flag:
                comp = "#"
            else:
                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

n = int(input())
s = input()
left = 0
right = len(re.findall('\.', s))

result = n
for i in range(n):
    if s[i] == '#':
        left += 1
    else:
        right -= 1
    tmp = left + right
    if tmp < result:
        result = tmp

print(result)

Submission status: Wrong Answer

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

answer = 200000
for i in range(1,len(s)):
    answer = min(answer, s[:i].count("#")+s[i:].count("."))

print(answer)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
M=S.count('.')
ans=M
sign = True

for i in range(len(S)):
	if S[i] == '#':
		M = M+1
	else:
		M = M-1
print(min(M,ans))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
ss = stdin.readline().rstrip()
sum = 0
left = 0
right = 0
for itr in range(0,N):
    if itr == N-1:
        break
    if ss[itr] == '#' and ss[itr+1] == '.':
        left = itr
        right = left + 1
        count_dot = 0
        count_sharp = 0
        while(right < N and ss[right] == '.'):
            count_dot += 1
            right += 1
        while(left >= 0 and ss[left] == '#'):
            count_sharp += 1
            left -= 1
        # print(count_dot, count_sharp)
        sum += min(count_dot, count_sharp)
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
preans = 0
pew = 0
bflag = 0
b2w = 0
for i, word in enumerate(s):
    if bflag == 0:
        if word == '#':
            bflag = 1
    else:
        if word == '.':
            b2w = 1
    if b2w == 1:
        if word == '.':
            preans += 1
skip = 1
ans = preans
wcount = 0
bcount = 0
for i, word in enumerate(s):
    if b2w > skip:
        ans = min(preans, preans + bcount - wcount)
        preans = preans + bcount - wcount
        skip += 1
        wcount = 0
        bcount = 0

    if word == '#':
        bcount += 1

    if bflag == 0:
        if word == '#':
            bflag = 1
    else:
        if word == '.':
            b2w += 1
            bflag = 0

    if b2w == skip and word == '.':
        wcount += 1
print(ans)

Submission status: Wrong Answer

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    s = lines[1]

    return (n, s)


def solve(n, s):
    
    ss = []
    count_w = 1
    count_b = -1
    before = s[0]
    for i, c in enumerate(s[1:]):
        if before == c:
            if c == ".":
                count_w = count_w + 1
            else:
                count_b = count_b - 1
        else:
            if before == ".":
                ss.append(count_w)
                count_w = 1
            else:
                ss.append(count_b)
                count_b = -1
        before = c

    if before == ".":
        ss.append(count_w)
    else:
        ss.append(count_b)

    if debug:
        log("ss=%s" % ss)


    if ss and ss[0] > 0:
       ss = ss[1:]
    if ss and ss[-1] < 0:
       ss = ss[:-1]
     
    count_w = sum([e for e in ss if e > 0])
    count_b = sum([e for e in ss if e < 0])

    result = min(count_w, abs(count_b))
    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
r = [S[:N].count("#") + S[N:].count(".") for _ in range(N)]  
print(min(r))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 10**9
for i in range(len(s)+1):
    sb = s[i:]
    sw = s[:i]
    w1 = sb.count('.')
    b1 = sb.count('#')
    ans = min((w1+b1),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
m=S[::-1]
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-l:
		 print(c-l)
	else:
		 print(a)
else:
	print(0)

Submission status: Wrong Answer

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

ans = N
for i in range(N):
  ret1 = S[i:].count('.')
  ret2 = S[:i].count('#')
  ans = min(ans, ret1+ret2)
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if s[0] == '#':
    left = 1
else:
    left = 0

right = s[1:].count('.')

p_min = left + right

for i in range(1, n):
    if s[i] == '.':
        right -= 1
    else:
        left += 1
    
    p_min = min(p_min, (left + right))

print(p_min)

Submission status: Wrong Answer

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

a = S.count('.')
r = a

for i in range(N):
    if S[0] == '#':
        a += 1
    else:
        r -= 1

print(min(r,r + a))

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)