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())
str = input()
minDistance = 0

black = "#"
white = "."
leftblack = 0
rightwhite = 0

for i in range(N):
    if str[i] == white:
        rightwhite += 1

minDistance += rightwhite

for j in range(1, N):
    if str[j] == black:
        leftblack += 1
    else:
        rightwhite -= 1
    if leftblack + rightwhite < minDistance:
        minDistance = leftblack+rightwhite

print("{}".format(minDistance))

Submission status: Wrong Answer

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

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

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:
n=int(input())
s=input()
r=s.count(".")
ans=[]
for i in s:
    if i=="#":
        r+=1
    else:
        r-=1
    ans.append(r)
print(min(ans))

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

    s2 = s[:-back]
    a = s.count(".")
    b = len(s) - a
    b2 = len(s2) - a

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

pro()

Submission status: Wrong Answer

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

cnt = N
cnt_left=0
cnt_right=S.count(".")
for i in range(N):
    if S[i] == "#":
        cnt_left += 1
    else:
        cnt_right -= 1

    if cnt_left + cnt_right < cnt:
        cnt = cnt_left + cnt_right
print(cnt)

Submission status: Wrong Answer

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

cnt = 0

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

print (cnt)

Submission status: Wrong Answer

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

for i, c in enumerate(s):
    if c == "#":
        s = s[i:]
        break

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

tmp_b = 0
tmp_w = 0
k = 0
flag = False

for c in s:
    if c == "#":
        if flag:
            if tmp_b > tmp_w:
                k += tmp_w
            else:
                k += tmp_b

            tmp_b = 0
            tmp_w = 0
            flag = False

        tmp_b += 1
    else:
        tmp_w += 1
        flag = True

print(k)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
S = input()
s_list = list(S)
temp_start = temp_end = N+1
count_1 = 0
count_2 = 0
for i in range(N):
    if s_list[i] == "#":
        temp_start = i
        break
if temp_start == N+1:
    print(0)
    sys.exit()
for i in range(N)[::-1]:
    if s_list[i] == ".":
        temp_end = i
        break
if temp_end == N+1:
    temp_end = N-1
for i in range(temp_start,temp_end + 1):
    if s_list[i] == "#":
        count_1 += 1
    else :
        count_2 += 1
print(min(count_1,count_2))

Submission status: Wrong Answer

Solution code:
SIRO = '.'
KURO = '#'
N = int(input())
S = input()
sLst = []
cnt = 1
if S[0] != '#':
    sLst.append(0)

for i in range(0, N - 1):
    if S[i] == S[i + 1]:
       cnt += 1
    else:
        sLst.append(cnt)
        cnt = 1
    if i == N - 2:
        sLst.append(cnt)
ans = 0
for i in range(0, len(sLst), 2):
    if len(sLst) >= i + 2:
        ans += min(sLst[i], sLst[i + 1])
print(ans)

Submission status: Wrong Answer

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

c=0
b=0
w=0
res=2*10^5
for i in range(n-1):
	if sl[i]=="#" and sl[i+1]==".":
		b = sl[:i].count("#")
		w = sl[i+1:].count(".")
		c = b + w
		#print(c)
		if c < res:
			res = c

if sl.count("#")==n or sl.count(".")==n:
	res = 0

print(res)

Submission status: Wrong Answer

Solution code:
import math
import re
n = int(raw_input())
s = raw_input()

prev = ''
ar = []
for i in s:
    if prev == '' or prev[0] == i:
        prev += i
    else:
        ar.append(prev)
        prev = i

ar.append(prev)

tmp = {
    "black": 0,
    "white":0
}
prev = ''

for a in ar:
    if prev.count('#') > 0:
        cur = {
            "black": tmp["black"] + len(prev),
            "white": tmp["white"]
        }
    else:
        cur = {
            "black": tmp["black"],
            "white": tmp["white"]
        }
    if a.count('.') > 0:
        tmp["white"] += len(a)

    if (tmp["black"] + tmp["white"]) >= (cur["black"] + cur["white"]):
        tmp["black"] = cur["black"]
        tmp["white"] = cur["white"]
    prev = a

print tmp["black"] + tmp["white"]

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
cnt = Counter(S)
B, W = cnt["#"], cnt["."]
left_b = 0
left_w = 0
total = float("inf")
for s in S:
    if s == "#":
        left_b += 1
    else:
        left_w += 1
    total = min(total, left_b + W - left_w  - 1)


print(total)

Submission status: Wrong Answer

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

min_count = 10**10
for i in range(1, N):
    black = S[:i].count("#")
    white = S[i:].count(".")
    if black + white < min_count:
        min_count = black + white

print(min_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = 0
l = 0
for i in range(n):
    if s[i:i+1] == ".":
        r += 1
ans = 10**9
for i in range(n):
    if s[i:i+1] == ".":
        r -= 1
    else:
        l += 1
    if l+r < ans:
        ans = l+r
print(ans)

Submission status: Wrong Answer

Solution code:

n = input()
s = input()
s_list = list(s)
dot_cnt =0
sharp_cnt = 0
for i in range(0, len(s_list)-1):
    # print("i", i)
    if s_list[i] == "#" and (s_list[i+1] == "."):
        for h in range(1,len(s_list)):
            if i+h == len(s_list):
                dot_cnt += h-1
                # print("dot_cnt_over", dot_cnt)
                break
            if s_list[i+h] == "#":
                dot_cnt += h-1
                # print("dot_cnt", dot_cnt)
                break
            # if i+h == len(s_list)-1:
            #     dot_cnt += h+1
            #     break
for i in range(1, len(s_list)):
    if s_list[i] == "." and (s_list[i-1] == "#"):
        for j in reversed(range(0,i)):
            if s_list[j] == ".":
                sharp_cnt += i-j-1
                break
            if j == 0:
                sharp_cnt += i
                break

print(min(dot_cnt, sharp_cnt))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
A=[]
a=S.count(".")
A.append(a)
for i in range(N):
    if S[0]=="#":
        a=a+1
    else:
        a=a-1
    A.append(a)
print(min(A))

Submission status: Wrong Answer

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

for i in range(len(S)):
    if S.find('#', i) == -1:
        break
    # 連続した'#'から'.'に変わった場合,'.'の出現をカウントする
    if S.find('#', i) != i:
        count += 1

print(count)

Submission status: Wrong Answer

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

white = 0
black = 0
first_black_index = 0
last_white_index = N

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

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

if first_black_index != N :
  S = S[first_black_index:last_white_index]

  for i in range(len(S)):
    if S[i] == "#":
      black +=1
    else:
      white +=1
  print(min(white,black))
else:
  print(0)

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 != na and s[rtmp] == '.':
                rig += 1
                rtmp += 1
            rlis.append(rig)
            lef = 0
            rig = 0
            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:
# -*- coding:utf-8 -*-

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

    kuro_num = 0
    siro_num = 0
    for moji in S:
        if moji == "#":
            kuro_num += 1
        else:
            siro_num += 1

    if siro_num == N:
        print(0)
        exit()

    # ..........############ のパターン
    rest_kuro_num = kuro_num
    rest_siro_num = siro_num
    ans = siro_num
    for i in range(0, len(S)):
        num = rest_siro_num
        if S[i] == "#":
            num += 1 + (kuro_num - rest_kuro_num)
            rest_kuro_num -= 1
        else:
            num += kuro_num - rest_kuro_num
            rest_siro_num -= 1
        ans = min(ans, num)

    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

result = l.count(".")
boundary = l.count(".")
for i in range(n):
    if l[i] == ".":
        boundary -= 1
    else:
        boundary += 1
result = min(result, boundary)    
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = s.count('.')

ans = 3*10**5
for i in s:
  if i =='#':
    w += 1
    
  else:
    w -=1
  ans = min(ans,w)
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 != 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())
if S == ['.'] * N:
    print(0)
    exit()
if S == ['#'] + ['.'] * (N - 1):
    print(1)
    exit()
ans = N - S.count('#')
ans0 = 10**9
for i in range(N):
    ans0 = min(ans, ans0)
    if S[i] == '.':
        ans -= 1
    else:
        ans += 1

print(ans0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
t=0
r=s.count(".")
e=s.count("#")
 
l=[]
for i in s:
    if i==".":
        r-=1
    else:
        t+=1
    l.append(r+t)
l.append(r+t)
print(min(l+[e]))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = 0
l = 0
for i in range(n):
    if s[i:i+1] == ".":
        r += 1
ans = 10**9
for i in range(n):
    if s[i:i+1] == ".":
        l -= 1
    else:
        r += 1
    if l+r < ans:
        ans = l+r
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if N == 1:
  print('0')
else:
  counter = 0
  for f, l in zip(S[:-1],S[1:]):
    if f == '#' and l == '.':
      counter += 1
  print(str(counter))

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

cnt=N
for i in range(N+1):
    left = S[0:i+1]
    right = S[i+1:N]
    if (left.count("#") + right.count(".")) <= cnt:
        cnt = left.count("#") + right.count(".")
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = s.count('.')
b = 0
ans = 3*10**5
for i in s:
  if i =='#':
    b += 1
    
  else:
    w -=1
  ans = min(ans,b+w)
print(ans)

Submission status: Wrong Answer

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

penals1 = []
penals2 = []
tmp1 = 0
tmp2 = 0

for i in range(N // 2 + 1):
    if S[i] == "#":
        tmp1 += 1
    
    if S[-(i+1)] == ".":
        tmp2 += 1
    penals1.append(tmp1)
    penals2.append(tmp1)

#min_p = [penals2[-1]] + [penals1[i] + penals2[-i] for i in range(N // 2 + 1)]
min_p = tmp1 + tmp2

j = 1
for i in range(N//2+1, N-1):
    if S[i] == "#":
        tmp1 += 1
    if S[-(i+1)] == ".":
        tmp2 += 1

    val1 = tmp1 + penals2[-j]
    val2 = penals1[-j] + tmp2
    val = min(val1, val2)
    if val < min_p:
        min_p = val
    j += 1

if S[N-1] == "#":
    tmp1 += 1
if S[0] == ".":
    tmp2 += 1

val = min(tmp1, tmp2)
if val < min_p:
    min_p = val

print(min_p)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
before=''
count=0
count_list=[]
for i,moji in enumerate(S):
    count+=1
    if moji!=before:
        before=moji
        count_list.append(count)
        count=0
    elif i-1==len(S):
        count_list.append(count)
cand=[]
ki=0
if S[0]=='.':
    count_list=count_list[1:]
    length=len(count_list)
    if length%2==1:
        ki=1
    for i in range(length//2+1):
        cand.append(sum(count_list[0:length-i*2-ki:2])+sum(count_list[length-i*2:length:2]))
else:
    length=len(count_list)
    if length%2==1:
        ki=1
    max_num=length//2
    for i in range(length//2+1):
        cand.append(sum(count_list[0:length-i*2-ki:2])+sum(count_list[length-i*2:length:2]))
        #print(length-i*2-ki)
        #print(count_list[i*2+1::2])
print(min(cand))

Submission status: Wrong Answer

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

count_w = 0
count_b = 0
s2=''

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

count_w = s2.count('.')
count_b = s.count('#')

print(min(count_w, count_b))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = list(input())
count_ = 0
count = 0
if "#" in S:
    for i in range(N):
        if S[i] == "#":
            S_right = S[i:]
            counter = collections.Counter(S_right)
            count = counter["#"]
            count_ = counter["."]
            break

print(min(count,count_))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
if S == ['.'] * N:
    print(0)
    exit()
ans = N - S.count('#')
ans0 = 10**9
for i in range(N):
    ans0 = min(ans, ans0)
    if S[i] == '.':
        ans -= 1
    else:
        ans += 1

print(ans0)

Submission status: Wrong Answer

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

white = 0
black = 0
first_black_index = 0

while S[first_black_index] == ".":
  first_black_index += 1
  if first_black_index == N:
    print(0)
    break

last_black_index = N
if first_black_index != N:
  while S[last_black_index-1] == "#":
    last_black_index -= 1
    if last_black_index == 0:
      print(0)
      break


if first_black_index != N and last_black_index != 0:
  S = S[first_black_index:last_black_index]

  for i in range(len(S)):
    if S[i] == "#":
      black +=1
    else:
      white +=1

  print(min(white,black))

Submission status: Wrong Answer

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

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

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

for i in len_s:
    if s[i] == "#":
        s = s[i::]
        print(s)
        break

count_sharp = s.count("#")
count_dot = s.count(".")
if min(count_dot, count_sharp) == 0:
    print(0)
else:
    print(min(count_dot, count_sharp))

Submission status: Wrong Answer

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

penals1 = []
penals2 = []
tmp1 = 0
tmp2 = 0

for i in range(N // 2 + 1):
    if S[i] == "#":
        tmp1 += 1
    
    if S[-(i+1)] == ".":
        tmp2 += 1
    penals1.append(tmp1)
    penals2.append(tmp1)

#min_p = [penals2[-1]] + [penals1[i] + penals2[-i] for i in range(N // 2 + 1)]
min_p = tmp1 + tmp2
print(min_p)

j = 1
for i in range(N//2+1, N-1):
    if S[i] == "#":
        tmp1 += 1
    if S[-(i+1)] == ".":
        tmp2 += 1

    val1 = tmp1 + penals2[-j]
    val2 = penals1[-j] + tmp2
    val = min(val1, val2)
    if val < min_p:
        min_p = val
    j += 1

if S[N-1] == "#":
    tmp1 += 1
if S[0] == ".":
    tmp2 += 1

val = min(tmp1, tmp2)
if val < min_p:
    min_p = val

print(min_p)

Submission status: Wrong Answer

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

ans = N

blk=0
white=S.count(".")

if white == 0:
	ans=0
else:
	for n in range(N):
		if S[n]=="#":
			blk += 1
		else:
			white -= 1
		ans=min(blk+white,ans)


print(ans)

Submission status: Wrong Answer

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

l = s.strip()
memo=[]
for i in range(0,n):
    memo.append(-1)
memo[0]=0

for i in range(1,n):
    if l[i] == ".":
        memo[i] = min(s[:i].count("#"), memo[i-1]+1)
    else:
        memo[i] = min(memo[i-1], s[:i].count(".")+1)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
s_list = list(s)
dot_cnt =0
sharp_cnt = 0
for i in range(0, len(s_list)-1):
    # print("i", i)
    if s_list[i] == "#" and (s_list[i+1] == "."):
        for h in range(1,len(s_list)):
            if i+h == len(s_list):
                dot_cnt += h-1
                # print("dot_cnt_over", dot_cnt)
                break
            if s_list[i+h] == "#":
                dot_cnt += h-1
                # print("dot_cnt", dot_cnt)
                break
            # if i+h == len(s_list)-1:
            #     dot_cnt += h+1
            #     break
for i in range(1, len(s_list)):
    if s_list[i] == "." and (s_list[i-1] == "#"):
        for j in reversed(range(0,i)):
            if s_list[j] == ".":
                sharp_cnt += i-j-1
                break
            if j == 0:
                sharp_cnt += i
                break

print(dot_cnt, sharp_cnt)

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()
t=0
r=s.count(".")
e=s.count("#")
 

x=[[k,len(list(v))]for k,v in groupby(s)]
#print(x)
l=[]
for n,m in x:
    if n==".":
        r-=m
    else:
        t+=m
    l.append(r+t)
l.append(r+t)
print(min(l+[e]))

Submission status: Wrong Answer

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

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

    kuro_num = 0
    siro_num = 0
    for moji in S:
        if moji == "#":
            kuro_num += 1
        else:
            siro_num += 1

    if siro_num == N:
        print(0)
        exit()

    rest_kuro_num = kuro_num
    rest_siro_num = siro_num
    ans = siro_num
    for i in range(0, len(S)):
        num = rest_siro_num
        if S[i] == "#":
            rest_kuro_num -= 1
            num += 1 + (kuro_num - rest_kuro_num)
        else:
            rest_siro_num -= 1
            num += kuro_num - rest_kuro_num
        ans = min(ans, num)

    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = []

for i in range(N+1):
  wcount = S[:i].count(".")
  bcount = S[i:].count("#")
  tmp = wcount + bcount
  ans.append(tmp)
print(min(ans))

Submission status: Wrong Answer

Solution code:
# 今のままだと駄目
N = int(input())
str = input()
minDistance = N
black = "#"
white = "."

for i in range(N):
    distance = 0
    loopnum = 0
    while (distance < minDistance and loopnum < N):

        for j in range(0, i):

            if str[j] == black:
                distance += 1
                loopnum += 1
            else:
                loopnum += 1

        for k in range(i, N):

            if str[k] == white:
                distance += 1
                loopnum += 1
            else:
                loopnum += 1

    if (loopnum == N):
        minDistance = distance

print("{}".format(minDistance))

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()
t=0
r=s.count(".")
e=s.count("#")
 

x=[[k,len(list(v))]for k,v in groupby(s)]
#print(x)
l=[]
for n,m in x:
    if n==".":
        r-=m
    else:
        t+=m
    l.append(r+t)
print(min(l+[e]))

Submission status: Wrong Answer

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

b=0
w=s.count(".")
ans = n
flag=False
for i in range(n):
    if w==0 or w==n:
        flag=True
        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(ans if flag==False else 0)

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()
t=0
r=s.count(".")
 

x=[[k,len(list(v))]for k,v in groupby(s)]
#print(x)
l=[]
for n,m in x:
    if n==".":
        r-=m
    else:
        t+=m
    l.append(r+t)
print(min(l))

Submission status: Wrong Answer

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

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

cotB = 0
cotW = 0
ans = b
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:
n = int(input())
s = input() + 'a'

counts = [s.count('#'), s.count('.')]

for i in range(n):
  if s[i] != s[i+1]:
    counts.append(s[:i+1].count('#') + s[i:].count('.'))
    
print(min(counts))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
cnt = Counter(S)
B, W = cnt["#"], cnt["."]
left_b = 0
left_w = 0
total = float("inf")
for s in S:
    if s == "#":
        left_b += 1
    else:
        left_w += 1
    total = min(total, left_b + W - left_w)


print(total)

Submission status: Wrong Answer

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

cnt = 0
stones = list(S)

# print(stones)
flg = False
cntKuro = 0
cntShiro = 0
for i in range(0, N):
    if flg:
        if stones[i] == ".":
            cntKuro += 1
        else:
            cntShiro +=1
    elif stones[i] == "#":
        flg = True

if cntKuro > cntShiro :
    print(cntShiro)
else:
    print(cntKuro)

Submission status: Wrong Answer

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

for i in len_s:
    if s[i] == "#":
        s = s[i::]
        break
count_sharp = s.count("#")
count_dot = s.count(".")
if min(count_dot, count_sharp) == n:
    print(0)
else:
    print(min(count_dot, count_sharp))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = [0 if si == "#" else 1 for si in S]
Sinv = S[::-1]
Bsum = [0] #境界より左にある黒の数
Wsum = [0] #境界より右にある白の数
for i in range(N):
    Bsum = Bsum + [Bsum[-1]+(1 if S[i]==0 else 0) ]
    Wsum = [Wsum[0]+(1 if Sinv[i]==1 else 0)] + Wsum
print([Bsum[i]+Wsum[i] for i in range(N+1)])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
cnt = Counter(S)
B, W = cnt["#"], cnt["."]
left_b = 0
left_w = 0
total = 1 << 20
for s in S:
    if s == "#":
        left_b += 1
    else:
        left_w += 1
    total = min(total, left_b + W - left_w)


print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w=b=0
mn=n
for sk in s:
    if sk=="#":
        b+=1
    else:
        w-=1
    if mn>b+w:
        mn=b+w
print(mn-w)

Submission status: Wrong Answer

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

res = 10**5
for i in range(n):
    a = s[:i].count("#")
    b = s[i:].count(".")
    res = min(res, a+b)
    
print(res)

Submission status: Wrong Answer

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

answer = 200000
b = 0
w = s.count(".")
if w == len(s) or s.count("#")==len(s):
    print(0)
else:
    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()
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")
                C = N - D + 1                
                print(N - C + B + 1)
            else:
                print(0)
        else:
            print(0)

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()
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 = 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:
N=int(input())
S=input()
same=''
before=''
count=0
count_list=[]
for i,moji in enumerate(S):
    count+=1
    if moji!=before:
        same+=moji
        before=moji
        count_list.append(count)
        count=0
    elif i-1==len(S):
        count_list.append(count)
cand=[]
length=len(count_list)
ki=0
if length%2==1:
    ki=1

if same[0]=='.':
    count_list=count_list[1:]
    max_num=length-1//2
    for i in range(length-1//2+1):
        cand.append(sum(count_list[0:max_num-i*2:2])+sum(count_list[i*2+1::2]))
else:
    max_num=length//2
    for i in range(length//2+1):
        cand.append(sum(count_list[0:length-i*2-ki:2])+sum(count_list[length-i*2:length:2]))
        #print(length-i*2-ki)
        #print(count_list[i*2+1::2])
print(min(cand))

Submission status: Wrong Answer

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

A = S.split('#')
B = S.split(".")

C = []
D = []
for i in A:
    C.append(len(i))
for i in B:
    D.append(len(i))

C = [i for i in C if not i == 0]
D = [i for i in D if not i == 0]

E = [0]
F = [0]
for i in C:
    E.append(i + E[-1])
for i in D:
    F.append(i + F[-1])



if len(E) > len(F):
    F.insert(0,0)
if len(F) > len(E):
    E.insert(0,0)

E = E[::-1]


ans = 10 ** 9
for i in range(len(E)):
    score = E[i] + F[i]
    if score < ans:
        ans = score

print(ans)

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

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] == '.':
        nw -= 1
    else:
        nb += 1
    ans = min(ans, nb + nw)

print(ans)

Submission status: Wrong Answer

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

cnt = 0
cnt1 = 0
cnt2 = 0
if N == 1:
    print("0")
    exit()
else:
    a=[0,0]
    for i in range(N):
        if S[i] == "#":
            a[0] += 1
        else:
            a[1] += 1
    if a[0] >= a[1]:
        for i in range(N-1):
            x = S[i]
            y = S[i+1]
            if x == "#" and y == ".":
                cnt += 1
                if cnt2 == 0:
                    S = S.replace(".","#",cnt1+1)
                else:
                    S = S.replace(".","#",1)
            if x == ".":
                cnt1 += 1
    else:
        for i in range(N-1):
            x = S[i]
            y = S[i+1]
            if x == "#" and y == ".":
                cnt += 1
                if cnt2 == 0:
                    S = S.replace("#",".",cnt1+1)
                else:
                    S = S.replace("#",".",1)
            if x == "#":
                cnt1 += 1

print(cnt)

Submission status: Wrong Answer

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

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

print(min_count)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    S = str(input())

    sharp_place = S.find("#")

    if sharp_place == -1:
        ok_pattern1 = "."*N
    else:
        ok_pattern1 = "."*sharp_place + "#" * (N-sharp_place)

    answer1 = 0

    for j in range(0, len(ok_pattern1)):
        if ok_pattern1[j] != S[j]:
            answer1 += 1

    print(answer1)