Problem:


Score : 300 points

Problem Statement

There are N stones arranged in a row. Every stone is painted white or black.
A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.

Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.
Find the minimum number of stones that needs to be recolored.

Constraints

1 \leq N \leq 2\times 10^5

S is a string of length N consisting of . and #.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the minimum number of stones that needs to be recolored.

Sample Input 1

3
#.#

Sample Output 1

1

It is enough to change the color of the first stone to white.

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N = ii()
S = input()

w_cnt = 0
b_cnt = 0

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

for i in S[::-1]:
    if i == '#':
        b_cnt += 1
    else:
        break

w = b = 0

for i in range(w_cnt, N-b_cnt):
    if S[i] == '#':
        b += 1
    else:
        w += 1

#print(w_cnt, b_cnt, w, b)
print(min(w, b))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N = I()
S = input()

s_siro = S.count(".")

siro = 0
kuro = 0
ans = N
for s in S:
    if s == "#":
        kuro += 1
    else:
        siro += 1
        
    ans = min(ans, (kuro + s_siro - siro))

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N = I()
S = input()

index_s = 0
index_k = N
while index_s < N and S[index_s] == ".":
    index_s += 1
while index_k > 0 and S[index_k-1 : index_k] == "#":
    index_k -= 1

if index_s == N or index_k == 0:
    print(0)
else:
    print(min(S[index_s : index_k].count("#"), S[index_s : index_k].count(".")))

Submission status: Wrong Answer

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

x=a.count(".")
y=a.count("#")

print(min(x,y))

Submission status: Wrong Answer

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

w = S.count('.')
b = N - w
ans = min(w, b)
l, r = 0, w

for si in S:
    if si == '#':
        l += 1  # 現時点iも含め左側に存在する黒の数
    else:
        r -= 1  # 現時点iも含め右側に存在する白の数
    ans = max(ans, l+r)

print(ans)

Submission status: Wrong Answer

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

stone = [[0, 0] for _ in range(N)]
before_w, before_b = 0, 0

for i in range(N):
    if S[i] == '.':
        stone[i] = [before_w+1, before_b]
        before_w += 1
    else:
        stone[i] = [before_w, before_b+1]
        before_b += 1

total_w, total_b = stone[-1]

#全ての石を黒に変える時
ans = S.count('.')

for i in range(N):
    w = stone[i][1]  # 左側にある黒を全てホワイトに
    tmp = total_w - stone[i][0]
    b = tmp if S[i]=='#' else tmp+1
    ans = min(ans, w+b)

print(ans)

Submission status: Wrong Answer

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

ix = S.find('#')
b_change = S[ix:].count('.')
w_change = S[:-1].count('#')

print(min(b_change, w_change))

Submission status: Wrong Answer

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

count_white = [0]*N

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

white_total = count_white[-1]
ans = 10**9
for i in range(N):
    num_black_left = i+1 - count_white[i]
    num_white_right = white_total - count_white[i]

    ans_temp = num_black_left + num_white_right

#    print i, ans_temp                                                                                                                                    

    ans = min(ans, ans_temp)

print ans

Submission status: Wrong Answer

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

l = []
used, count = set(s[0]), 1
for i in s[1:]:
    if i in used:
        count += 1
    else:
        t = used.pop()
        l.append((t, count))
        count = 1
        used = set(i)
if count:
    l.append((used.pop(), count))

size = len(l)
ans1, ans2 = 0, 0
if l[0][0] == "#":
    for i in range(1, size, 2):
        ans1 += l[i][1]
    for i in range(0, size, 2):
        ans2 += l[i][1]
else:
    for i in range(1, size, 2):
        ans1 += l[i][1]
    for i in range(2, size, 2):
        ans2 += l[i][1]

ans = min(ans1, ans2)
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(N-1):
    if s[i]=="#" and s[i+1]==".":
        s[i+1] = "#"
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
lS = len(S)
l = 0
bw = [0, 0]
for i in range(lS):
    if (S[i] == "."):
        bw[1] += 1

ans = sum(bw)
for i in range(lS):
    if (S[i] == "#"):
        bw[0] += 1
    if (S[i] == "."):
        bw[1] -= 1


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
lS = len(S)
l = 0
bw = [0, 0]
for i in range(lS):
    if (S[i] == "."):
        bw[1] += 1

ans = 10**9
for i in range(lS):
    if (S[i] == "#"):
        bw[0] += 1
    if (S[i] == "."):
        bw[1] -= 1

    if (ans > sum(bw)):
        ans = sum(bw)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
lS = len(S)
l = 0
while (S[l] == ".")and(l != lS-1):
    l += 1
r = lS
while (S[r - 1] == "#") and (r != 0):
    r -= 1

st = S[l:r]
bw = [0, 0]
for i in range(len(st)):
    if (st[i] == "#"):
        bw[0] += 1
    else:
        bw[1] += 1

print(min(bw))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
lS = len(S)
i = 0
while (S[i] == ".")and(i != lS-1):
    i += 1

st = S[i:lS]
bw = [0, 0]
for i in range(len(st)):
    if (st[i] == "#"):
        bw[0] += 1
    else:
        bw[1] += 1

print(min(bw))

Submission status: Wrong Answer

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

a = S.count(".")
b = S.count("#")
if a == n or b == n:
    print(0)
else:
    print(min(a, b))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
corner=0
start=0
for i in range(0,N):
    if S[i]=='.':
        corner+=1
    else:
        start=i
        break

black=0
for i in range(start,N):
    if S[i]=='#':
        black+=1

print(N-corner-black)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
split_list = []
part = ""
for s in S:
    if not part:
        part += s
    elif s in part:
        part += s
    else:
        split_list.append(part)
        part = s
split_list.append(part)

count = 0

# print(split_list)
for idx, part in enumerate(split_list):
    if '#' in part and idx+1 < len(split_list):
        count += min(len(part), len(split_list[idx+1]))
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
index = 0
for i in range(n):
  if s[i] == '#':
    index = i+1
    break
print(n-index-s[index-1:].count('.'))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
index = 0
for i in range(n):
  if s[i] == '#':
    index = i+1
    break
print(n-index-s.count('.'))

Submission status: Wrong Answer

Solution code:
from decimal import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    # N = I()
    s = S()
    N = len(s)
    white = [0 if s[i] == '.' else 1 for i in range(N)]
    count = sum(white)
    lst = set()
    lst.add(count)

    for i in range(N-1, -1, -1):
        if white[i]:
            count -= 1
        else:
            count += 1
        lst.add(count)
    print(min(lst))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from decimal import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    t = S()
    # N = len(t)
    s1 = [t[i] for i in range(len(t))]
    s2 = [t[i] for i in range(len(t))]
    ans1 = 0
    ans2 = 0

    for i in range(N-1):
        if s1[i] == '#' and s1[i+1] == '.':
            ans1 += 1
            s1[i+1] = '#'

    for i in range(N-2, -1, -1):
        if s2[i] == '#' and s2[i+1] == '.':
            s2[i] = '.'
            ans2 += 1

    # print(ans1, ans2)
    print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from decimal import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    t = S()
    s1 = [t[i] for i in range(len(t))]
    s2 = [t[i] for i in range(len(t))]
    ans1 = 0
    ans2 = 0

    for i in range(N-1):
        if s1[i] == '#' and s1[i+1] == '.':
            ans1 += 1
            s1[i+1] = '#'

    for i in range(N-1):
        if s2[i] == '#':
            ans2 += 1

    print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N = I()
S = input()

ans1 = INF
idx = S.find('#')
if idx >= 0:
    ans1 = S[idx + 1:].count('.')

ans2 = 0
found = False
for c in reversed(S):
    if not found and c == '#':
        continue
    found = True
    if c == '#':
        ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N = I()
S = input()

ans1 = INF
idx = S.find('#')
if idx >= 0:
    ans1 = S[idx + 1:].count('.')

ans2 = S[:N - 1].count('#')
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
def main():
    length = int(input())
    stones = list(input())
    white = [0] * length
    if stones[0] == ".":
        white[0] = 1
    for i in range(1, length):
        if stones[i] == ".":
            white[i] = white[i - 1] + 1
        else:
            white[i] = white[i - 1]
    answer = float("inf")
    for i in range(length):
        answer = min(answer, i + 1 + white[-1] - 2 * white[i])
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

wn = s.count('.')
bn = n - wn
ans = min(wn,bn)

lw = 0
lb = 0
for i in range(n):
  if s[i]=='.':
    lw += 1
  else:
    lb += 1      
  ans = min(ans, lw + (bn - lb))
  
print(ans)

Submission status: Wrong Answer

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

wn = s.count('.')
bn = n - wn
print(min(wn,bn))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = list(input())
T = copy.copy(S)
ans = 0
ans2 = 0
for i in range(N-1):
    if S[i] == '#' and S[i+1] == '.':
        ans += 1
        S[i+1] = '#'
for i in range(N-2, -1, -1):
    if T[i] == '#' and T[i+1] == '.':
        ans2 += 1
        T[i] = '.'
print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = list(input())
T = copy.copy(S)
ans = 0
ans2 = 0
for i in range(N-1):
    if S[i] == '#' and S[i+1] == '.':
        ans += 1
        S[i+1] = '#'
for i in range(N-1):
    if T[i] == '#' and T[i+1] == '.':
        ans2 += 1
        T[i] = '.'
print(min(ans, ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
def runLength(s):
  if len(s) == 0: return []
  if len(s) == 1: return [(s, 1)]
  res = []
  lc = 1
  for i in range(1, len(s)):
    if s[i-1] == s[i]:
      lc += 1
    else:
      res.append((s[i-1], lc))
      lc = 1
  res.append((s[i], lc))
  return res

ans = 0
S = runLength(input())

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

Submission status: Wrong Answer

Solution code:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    if "#" not in s:
        print(0)
    else:
        index = s.index("#")
        use = s[index:]
        print(len(use)-use.count("#"))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
if S=='#'*N or S=='.'*N:
  print(0)
  exit()
rightB=0
for i in S:
  if i=='#':
    rightB+=1
rightW=N-rightB
leftB=0
leftW=0
ans=rightB
for i in range(N):
  if S[i]=='.':
    leftW+=1
    rightW-=1
    d=rightW+leftB
    ans=min(ans,d)
  else:
    leftB+=1
    rightB-=1
    d=rightW+leftB
    ans=min(ans,d)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
rightB=0
for i in S:
  if i=='#':
    rightB+=1
rightW=N-rightB
leftB=0
leftW=0
ans=rightB
for i in range(N):
  if S[i]=='.':
    leftW+=1
    rightW-=1
    d=rightW+leftB
    ans=min(ans,d)
  else:
    leftB+=1
    rightB-=1
    d=rightW+leftB
    ans=min(ans,d)
print(ans)

Submission status: Wrong Answer

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

ans = [0, 0]
prev = [0, 0]

for i in range(n):
        if s[i]=="." and prev[0]=="#":
                ans[0] += 1
                prev[0] = "#"
        else: prev[0] = s[i]

        if s[n-i-1]=="#" and prev[1]==".":
                ans[1] += 1
                prev[1] = "."
        else: prev[1] = s[n-i-1]

print(min(ans))

Submission status: Wrong Answer

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

ans = prev = 0
for i in range(n):
        if s[i]=="." and prev=="#":
                ans += 1
                prev = "#"
        else: prev = s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
print(min(map(list(open(0))[1].count,"#.")))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    if len(set(S)) == 1:
        return print(0)
    st = -1
    for i, s in enumerate(S):
        if s == "#":
            st = i
            break
    ans = S[st:].count(".")  # from 白 to 黒
    st = -1
    flag = False
    for i, s in enumerate(S[::-1]):
        if not(flag) and s == ".":
            flag = True
        if flag and s == "#":
            st = -(i+1)
            break
    ans = min(ans, S[:st].count("#") + 1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    if len(set(S)) == 1:
        return print(0)
    st = -1
    for i, s in enumerate(S):
        if s == "#":
            st = i
            break
    print(S[st:].count("."))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w = 0
b = 0
for i in range(N):
    if S[i] == ".":
        w += 1
    else:
        b += 1
print(min(w,b))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
f=S.find('#')
t=S.rfind('.')
SS=S[f:t+1]
N = len(SS)
x = SS.count('#')
print(min(N-x,x))

Submission status: Wrong Answer

Solution code:
import numpy as np
def f(lst):
    return np.cumsum(lst)

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

res1 = s.count('.')
res2 = s.count('#')

a = [0]*n
b = [0]*n

for i in range(n):
    if s[i]=='.':
        a[i] += 1
    else:
        b[i] += 1
cum_a = f(a).tolist()
cum_b = f(b).tolist()

res3 = np.inf
for i in range(n):
    if a[i]==1:
        res3 = min(res3, cum_a[i]+(res2-cum_b[i]))
print(min(res1, res2, res3))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
  import itertools
  
  n,s=int(input()),list(input())
  ans=0
  c=0
  m=""
  for a,b in itertools.groupby(s):
    if c==0:
      m=a
      c+=1
    else:
      if m=="#" and a==".":
        ans+=len(list(b))
  print(ans)
  
if __name__=="__main__":
  main()

Submission status: Wrong Answer

Solution code:
def main():
  from collections import deque
  import sys
  
  n,s=int(input()),list(input())
  c=s[1:].count(".")
  print(c)
  
if __name__=="__main__":
  main()

Submission status: Wrong Answer

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

white_count = 0
safe_black_count = 0
safe_white_count = 0

for i in range(N-1,-1,-1):
  if S[i] == "#":
    safe_black_count += 1
  else:
    break
    
for i in range(N):
  if S[i] == ".":
    safe_white_count += 1
  else:
    break
    
for i in range(N):
  if S[i] == ".":
    white_count += 1

error_black_count = N-white_count-safe_black_count
error_white_count = white_count-safe_white_count

print(min(error_white_count,error_black_count))

Submission status: Wrong Answer

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

error_index = []
white_count = 0
safe_black_count = 0

for i in range(N-1,-1,-1):
  if S[i] == "#":
    safe_black_count += 1
  else:
    break
    
for i in range(N):
  if S[i] == ".":
    white_count += 1

error_black_count = N-white_count-safe_black_count

print(min(white_count,error_black_count))

Submission status: Wrong Answer

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

sum_blacks = [0] * (N + 1)
for i in range(N):
    if S[i] == "#":
        sum_blacks[i+1] = sum_blacks[i] + 1
    else:
        sum_blacks[i+1] = sum_blacks[i]
print(sum_blacks)
ans = float('inf')
for i in range(N+1):
    l_whites = i - sum_blacks[i]
    l_blacks = sum_blacks[i]
    r_blacks = sum_blacks[-1] - l_blacks
    r_whites = N - l_whites - l_blacks - r_blacks
    ans = min(ans, l_blacks + r_whites)
print(ans)

Submission status: Wrong Answer

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

w_num=0
b_num=0
w_l=[]
b_l=[]

for i in s:
 if i=='.':
  w_num+=1
 else:
  b_num+=1
 w_l.append(w_num)
 b_l.append(b_num)

ans=10**5
for i in range(n):
 ans=min(ans,b_l[i]+(w_num-w_l[i]))
print(ans)

Submission status: Wrong Answer

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

check=0
for i in range(n):
 if s[i]=='#':
  l=s[i:]
  c_1=l.count('.')
  c_2=l.count('#')
  print(c_1 if c_1<=c_2 else c_2)
  exit()
print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a,b=0,0 # a:'.'の個数 b:'#'の個数
x=0 # x:'.'の個数
for i in s:
    if i==".":
        x+=1
ans=10**7
for i in s:
    if i==".":
        a+=1
    else:
        b+=1
    ans=min(ans,b+x-a)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
def is_all(s):
    for i in range(1,len(s)):
        if s[i]!=s[i-1]:
            return False
    return True
if is_all(s):
    print(0)
    exit()
for i in range(n):
    if s[i]=="#":
        l=i
        break
for i in range(n-1,-1,-1):
    if s[i]==".":
        r=i
        break
a,b=0,0 # a:'.'の個数 b:'#'の個数
for i in range(l,r+1):
    if s[i]==".":
        a+=1
    else:
        b+=1
print(min(a,b))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
def is_all(s):
    for i in range(1,len(s)):
        if s[i]!=s[i-1]:
            return False
    return True
if is_all(s):
    print(0)
    exit()
for i in range(n):
    if s[i]=="#":
        l=i
        break
for i in range(n-1,-1,-1):
    if s[i]==".":
        r=i
        break
a,b=1,0 # a:'.'の個数 b:'#'の個数
for i in range(l,r):
    if s[i]==".":
        a+=1
    else:
        b+=1
print(min(a,b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if "#." not in s:
    print(0)
else:
    print(min(s.count("."), s.count("#")))

Submission status: Wrong Answer

Solution code:
input()
s=input()
cnt=s.count(".")
l=[]
for i in s:
    cnt= cnt-1 if i=="." else cnt+1
    l.append(cnt)
print(min(l))

Submission status: Wrong Answer

Solution code:
input()
s=input()
cnt=s.count(".")
for i in s:
    cnt= cnt-1 if i=="." else cnt+1
print(cnt)

Submission status: Wrong Answer

Solution code:
import re
N=int(input())
s=input()
s=re.sub(r"^\.+","",s)
s=re.sub(r"#$","",s)
print(min(s.count("."),s.count("#")))

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[i for i in input()]
L=R=True
ss=s[:]
for i in range(N):
    if L or R:
        if L and s[i]==".":
            ss.pop(0)
        else:
            L=False
        if R and s[-1-i]=="#":
            ss.pop(-1)
        else:
            R=False
    else:
        break
print(min(ss.count("."),ss.count("#")))

Submission status: Wrong Answer

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

sha_flag = False

sha_num = 0
dot_num = 0

# "(" = "#" 
# ")" = "."

for i in range(N):

    if sha_flag == False:
        if S[i] == "#":
            sha_flag = True
    else:
        if S[i] == ".":
            dot_num += 1

    if S[i] == "#":
        sha_num += 1

print(min(sha_num,dot_num))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = 0
b = 0
flag = 0
i = 0
ind = 0
for x in s:
    if i > 0:
        if s[i - 1] == "#" and x == "." and flag==0:
            w += 1
            b += 1
            ind = i - 1
            flag = 1
        elif flag == 1 and x == ".":
            w += 1
        elif flag == 1 and x == "#":
            b += 1
    i += 1
if flag == 1:
    for i in range(0, ind):
        if s[i] == "#":
            b += 1
print(min(w, b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = 0
b = 0
flag = 0
i = 0
for x in s:
    if i > 0:
        if s[i - 1] == "#" and x == "." and flag==0:
            w += 1
            b += 1
            flag = 1
        elif flag == 1 and x == ".":
            w += 1
        elif flag == 1 and x == "#":
            b += 1
    i += 1
print(min(w, b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
a = 0
flag = 0
i = 0
for x in s:
    if i > 0:
        if s[i - 1] == "#" and x == ".":
            c += 1
            a += 1
            flag = 1
        elif flag == 1 and x == ".":
            c += 1
        elif flag == 1 and x == "#":
            a += 1
    i += 1
print(min(c, a))
# print(min(w, b, c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
flag = 0
i = 0
for x in s:
    if i > 0:
        if s[i - 1] == "#" and x == ".":
            c += 1
            flag = 1
        elif flag == 1 and x == ".":
            c += 1
    i += 1
print(c)
# print(min(w, b, c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = 0
w = 0
c = 0
flag = 0
i = 0
for x in s:
    if x == ".":
        w += 1
    else:
        b += 1
    if i > 0:
        if s[i - 1] == "#" and x == ".":
            c += 1
            flag = 1
        elif flag == 1 and x == ".":
            c += 1
    i += 1
print(min(w, b, c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = 0
w = 0
for x in s:
    if x == ".":
        w += 1
    else:
        b += 1
print(min(w, b))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w_cnt=s.count(".")

ans=[]
b=0
w=w_cnt

for i in range(n):
    if s[i]=="#":
        b+=1
    else:
        w-=1
    ans.append(b+w)

print(min(ans))

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = "."+stdin.readline().rstrip()
kuro = s.count("#")
shiro = n-kuro
mi = shiro
k = 0
sh = shiro
for i in range(n):
    if s[i] == "#":
        k += 1
    else:
        sh -= 1
    mi = min(mi,kuro+shiro)
print(mi)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = "."+stdin.readline().rstrip()
kuro = s.count("#")
shiro = n-kuro
mi = shiro
for i in range(n):
    if s[i] == "#":
        kuro += 1
    else:
        shiro -= 1
    mi = min(mi,kuro+shiro)
print(mi)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = "."+stdin.readline().rstrip()
point = 0
point2 = 0
for i in s:
    if i == ".":
        point += 1
    else:
        break
for j in s[::-1]:
    if j == "#":
        point2 += 1
    else:
        break
s = s[point:len(s)-point2]
S = len(s)
sharp = s.count("#")
flat = S-sharp
print(min(S-sharp,S-flat))

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = "."+stdin.readline().rstrip()
point = 0
for i in s:
    if i == ".":
        point += 1
    else:
        break
s = s[point:]
S = len(s)
sharp = s.count("#")
flat = S-sharp
print(min(S-sharp,S-flat))

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = "."+stdin.readline().rstrip()
print(s.count("#."))

Submission status: Wrong Answer

Solution code:
# TLEkuraisou 

n=int(input())
s=input()
sr=s[::-1]

black_sum=s.count("#")
white_sum=n-black_sum
black=0
white=0
for i in range(n):
    if s[i]==".":
        black=i
        
        break
#print("b:",black)
for i in range(n):
    if sr[i]=="#":
        white=i
        break
#print("w:",white)
ans=min(black_sum-black,white_sum-white)
print(ans)

Submission status: Wrong Answer

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

black_sum=s.count("#")
white_sum=n-black_sum
black=0
white=0
for i in range(n):
    if s[i]==".":
        black=i
        break
    
for i in range(n):
    if s[~i]=="#":
        white=~i+n
        break
    
ans=min(black_sum-black,white_sum-white)
print(ans)

Submission status: Wrong Answer

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

black_sum=s.count("#")
white_sum=n-black_sum
black=0
white=0
for i in range(n):
    if s[i]==".":
        black=i
        break
    
for i in range(n):
    if s[~i]=="#":
        white=~i+n
        
ans=min(black_sum-black,white_sum-white)
print(ans)

Submission status: Wrong Answer

Solution code:
# TLEkuraisou 

n=int(input())
s=input()
ss=s
cnt=0
for i in range(n):
    a=s.count(".#")
    if a==0:
        break
    cnt+=a
    s=s.replace(".#","..")
cnt2=0
for i in range(n):
    aa=ss.count(".#")
    if aa==0:
        break
    cnt2+=aa
    ss=ss.replace(".#","##")
    


print(min(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
# TLEkuraisou 

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

cnt=0
for i in range(n):
    a=s.count(".#")
    if a==0:
        break
    cnt+=a
    s=s.replace(".#","..")
    
print(cnt)