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()
counter = 0
counter = s.count('.')
result = n
for i in s:
    if i == '#':
        counter += 1
    else:
        counter -= 1
    result = min(result, counter)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
counter = 0
for i in range(len(s)):
    if s[i] == '.':
        counter += 1
result = n
for i in range(len(s)):
    if s[i] == '#':
        counter += 1
    else:
        counter -= 1
    result = min(result, counter)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count_b_l = 0
count_w_r = 0
for i in range(len(s)):
    if s[i] == '.':
        count_b_l += 1
result = []
for i in range(len(s)):
    if s[i] == '#':
        count_w_r += 1
    else:
        count_b_l -= 1
    result.append(count_b_l+count_w_r)
print(min(result))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count_b_l = 0
count_w_r = 0
for i in range(len(s)):
    if s[i] == '.':
        count_w_r += 1
result = []
for i in range(len(s)):
    if s[i] == '#':
        count_w_r += 1
    else:
        count_b_l -= 1
    result.append(count_b_l+count_w_r)
print(min(result))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count_b_l = 0
count_w_r = 0
for i in range(n):
    if s[i] == '.':
        count_w_r += 1
result = []
for i in range(len(s)):
    if s[i] == '#':
        count_b_l += 1
    else:
        count_w_r -= 1
    result.append(count_b_l+count_w_r)
print(min(result))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
c = 0
ran = []
i = 0
while i+c <= n:
    if i+c < n:
        if s[i] == s[c+i]:
            c += 1
        else:
            ran.append([s[i], c])
            i += c
            c = 0
    else:
        ran.append([s[i], c])
        c +=1
ran = ran[::-1]
# '#' is brack
result = []
if ran[0][0] == '#':
    counter_1 = 0
    counter_2 = 0
    for i in range(1, len(ran)):
        if i %2 == 0:
            counter_1 += ran[i][1]
        else:
            counter_2 += ran[i][1]
    print(min([counter_1, counter_2]))
else:
    counter_1 = 0
    counter_2 = 0
    for i in range(len(ran)):
        if i%2 == 0:
            counter_1 += ran[i][1]
        else:
            counter_2 += ran[i][1]
    print(min([counter_1, counter_2]))

Submission status: Wrong Answer

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

counter = 0
for i in range(1, n):
    if s[i-1] == '#' and s[i] == '.':
        counter += 1
    else:
        continue
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans=0
cnt=0
for i in range(n):
  if s[i-1]=='#':
    cnt+=1
  elif cnt>0:
    cnt=0
    ans+=1
print(ans)

Submission status: Wrong Answer

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

ans=0
cnt=0
for i in range(n):
  if s[i-1]=='#':
    cnt+=1
  elif cnt>0:
    cnt-=1
    ans+=1
print(ans)

Submission status: Wrong Answer

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

ans2=s[:-1].count('#')
ans=0
for i in range(n):
  if s[i-1]=='#':
    ans+=1
print(min(ans,ans2))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans=0
for i in range(1,n):
  if s[i-1]=='#' and s[i]=='.':
    s[i]='#'
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input())
r = 0
h = 0
r1 = 0
l1 = 0
l2 = S.count(".")
for i in range(n-1):
  if S[i] == "#":
    r1 += 1
  else:
    l1 += 1
  if S[i] == "#" and S[i+1] == ".":
    r = max(r, r1)
    h = max(h, l2-l1)  
print(min(r,h))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
l_b=0
r_w=s.count(".")
ans=n
if s=="#"*n:
	ans=0
for x in s:
	if x=="#":
		l_b+=1
	else:
		r_w-=1
	ans=min(ans,l_b+r_w)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
black = sum(map(len,s.split("#")[1:]))
white = sum(map(len,s.split(".")))
print(min(black,white))

Submission status: Wrong Answer

Solution code:
n = int(input())
print(sum(map(len,input().split("#")[1:])))

Submission status: Wrong Answer

Solution code:
print(sum(map(len,input().split("#")[1:])))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
b, w = 0, 0
for x in range(len(s) - 1):
    if s[x] == '#' and s[x+1] == '.': w += 1
    elif s[x] == '.' and s[x+1] == '#': b += 1
print(max(b, w))

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 = list(input())
cnt = 0
for x in range(len(s) - 1):
    if s[x] == '#' and s[x+1] == '.':
        s[x+1] = '#'
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w=s.count(".")
ww=0
b=s.count("#")
bb=0
ans=[]
for i in range(n):
	if s[i]==".":
		w-=1
		ww+=1
	else:
		b-=1
		bb+=1
	ans.append(bb+w)
print(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

n = int(input())
S = input()
f = [0] * (n+1)
for i in range(n):
    f[i+1] = f[i] + (S[i] == '#')
g = [0] * (n+1)
for i in range(n):
    g[i+1] = g[i] + (S[i] == '.')
ans = min(f[n], g[n])
lst = []
for i in range(n-1):
    if S[i:i+2] == '#.':
        lst.append(i)
for i, j in zip(lst, lst[1:]):
    ans = min(ans, f[i+1]+g[n]-g[j])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

n = int(input())
S = input()
ans = 0
l = 0
while l < n and S[l] == '.':
    l += 1
for r in range(l+1, n):
    if S[r-1:r+1] == '.#':
        c = S[l:r].count('.')
        ans += min(c, r-l-c)
        l = r
if S[-1] == '.':
    c = S[l:n].count('.')
    ans += min(c, n-l-c)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

n = int(input())
S = input()
ans = 0
l = 0
while l < n and S[l] == '.':
    l += 1
m = r = l
for r in range(l, n-1):
    if S[r:r+2] == '#.':
        m = r
    if S[r:r+2] == '.#':
        ans += min(r-m, m-l+1)
        l = r+1
if S[-1] == '.':
    ans += min(r-m+1, m-l+1)
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
s=input()
def sv(s,t):
  rt=i=0
  for c in s:
    if c==t:
      rt=len(s)-i-s[i:].count(t)
      break
    i+=1
  return rt
print(min(sv(s,'#'),sv(s[::-1],'.')))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions,math,sys
from collections import Counter
n = int(input())
s = list(input())
cnt = Counter(s)
white_l = 0
black_l = 0
min = 10**9
for i in range(n):
    if s[i] == '#':
        black_l += 1
        cnt['#'] -= 1
    else:
        white_l += 1
        cnt['.'] -= 1
    if black_l + cnt['.'] < min:
        min = black_l + cnt['.']
print(min)

Submission status: Wrong Answer

Solution code:
import fractions,math,sys
from collections import Counter
n = int(input())
s = list(input())
min = 10**9
for i in range(n):
    l = s[:i]
    r = s[i:]
    cnt_l = Counter(l)
    cnt_r = Counter(r)
    if cnt_l['#'] + cnt_r['.'] < min:
        min = cnt_l['#'] + cnt_r['.']
print(min)

Submission status: Wrong Answer

Solution code:
import fractions,math,sys,collections
n = int(input())
s = input()
s = list(s)
cnt_s = cnt_e = collections.Counter(s)
for i in range(n):
    if s[i] == '.':
        cnt_s['.'] -= 1
    else:
        break
for i in range(n)[::-1]:
    if s[i] == '#':
        cnt_e['#'] -= 1
    else:
        break
print(min(cnt_s['.'],cnt_s['#'],cnt_e['.'],cnt_e['#']))

Submission status: Wrong Answer

Solution code:
import fractions,math,sys,collections
n = int(input())
s = input()
s = list(s)
cnt = collections.Counter(s)
for i in range(n):
    if s[i] == '.':
        cnt['.'] -= 1
    else:
        break
print(min(cnt['.'],cnt['#']))

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()
a=0
if "#." in S:
  a=min(S.count("."),S.count("#"))
print(a)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
a=0
if "#." in S:
  a=S.count(".")
print(a)

Submission status: Wrong Answer

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

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

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

print(min(left,right))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
S = list(str(input()))

left = 0

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

right = 0

for i in range(N):
    j = (N-1)-i
    if(S[j] == '.'):
        T = S[:j+1]
        right = T.count('#')
        break

print(min(left,right))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
S = list(str(input()))

for i in range(N):
    if(S[i] == '#'):
        S = S[i:]
        print(S.count('.'))
        sys.exit()

print(0)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
S = list(str(input()))

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

    if(i == N-1):
        print(0)
        sys.exit()

print(S.count('.'))

Submission status: Wrong Answer

Solution code:
# #.がなければ文句ない
n = int(input())
arr = list(input())
try:
    first_black = arr.index("#")
except:
    print(0)
    exit()

c = 0
for i in range(first_black, n):
    if arr[i] == ".":
        c += 1

print(min(arr.count("#"), c))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
a = list(S)
b = list(S)
aa = list(S)
bb = list(S)
ans = 0
aans = 0
bns = 0
bbns = 0
for i in range(n-2,-1,-1):
    if a[i] == "#" and a[i+1] == ".":
        ans += 1
        a[i+1] = "#"

for i in range(n-2,-1,-1):
    if b[i] == "#" and b[i+1] == ".":
        bns += 1
        b[i] = "."

for i in range(n-1):
    if aa[i] == "#" and aa[i+1] == ".":
        aans += 1
        aa[i+1] == "#"

for i in range(n-1):
    if bb[i] == "#" and bb[i+1] == ".":
        bbns += 1
        bb[i] == "."
print(min(ans,aans,bns,bbns))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
a = list(S)
b = list(S)
ans = 0
bns = 0
for i in range(n-2,-1,-1):
    if a[i] == "#" and a[i+1] == ".":
        ans += 1
        a[i] = "."
for i in range(n-1):
    if a[i] == "#" and a[i+1] == ".":
        bns += 1
        a[i+1] = "#"
print(min(ans,bns))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
a = list(S)
ans = 0
for i in range(n-2,-1,-1):
    if a[i] == "#" and a[i+1] == ".":
        ans += 1
        a[i] = "."

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
s = list(S)
j = list(S)
ans = 0
aans = 0
for i in range(n-2,-1,-1):
    if s[i] == "#" and s[i+1] == ".":
        ans += 1
        s[i+1] = "#"
for i in range(n-1):
    if j[i] == "#" and j[i+1] == ".":
        aans += 1
        j[i+1] == "#"
print(min(ans,aans))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
s = list(S)
j = list(S)
ans = 0
aans = 0
for i in range(n-2,-1,-1):
    print(s[i])
    if s[i] == "#" and s[i+1] == ".":
        ans += 1
        s[i+1] = "#"
for i in range(n-1):
    if j[i] == "#" and j[i+1] == ".":
        aans += 1
        j[i+1] == "#"
print(min(ans,aans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
ans = 0
for i in range(n-2,-1,-1):
    if s[i] == "#" and s[i+1] == ".":
        ans += 1
        s[i+1] = "#"
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#Tenka1 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
s = input()
d = [0]+[1 if s[i] == "#" else 0 for i in range(n)]
d = list(accumulate(d))
ans = 0
for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.':
        cnt1 = d[-1] - d[i+1]
        cnt2 = n - (i+1) - cnt1
        if cnt1 < cnt2:
            cnt3 = d[i+1]-d[0]
            ans += min(cnt2,cnt3)
            break
        else:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#Tenka1 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
s = input()
d = [1 if s[i] == "#" else 0 for i in range(n)]
d = list(accumulate(d))
ans = 0
for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.':
        cnt1 = d[-1] - d[i]
        cnt2 = n - (i+1) - cnt1
        if cnt1 < cnt2:
            ans += cnt2
            break
        else:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#Tenka1 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
s = input()
d = [1 if s[i] == "#" else 0 for i in range(n)]
d = list(accumulate(d))
ans = 0
for i in range(n):
    if s[i] == '#':
        cnt1 = d[-1] - d[i]
        cnt2 = n - (i+1) - cnt1
        if cnt1 <= cnt2:
            ans += cnt2
            break
        else:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#Tenka1 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
s = input()
d = [1 if s[i] == "#" else 0 for i in range(n)]
d = list(accumulate(d))
ans = 0
for i in range(n):
    if s[i] == '#':
        cnt1 = d[-1] - d[i]
        cnt2 = n - (i+1) - cnt1
        if cnt1 <= cnt2:
            ans += cnt2
            break
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#Tenka1 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
s = input()
d = [1 if s[i] == "#" else 0 for i in range(n)]
d = list(accumulate(d))
ans = 0
for i in range(n):
    if s[i] == '#':
        cnt1 = d[-1] - d[i]
        cnt2 = n - (i+1) - cnt1
        if cnt1 < cnt2:
            ans += 1
    else:
        cnt1 = d[-1] - d[i]
        cnt2 = n - (i+1) - cnt1
        if cnt1 > cnt2:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# 2019/07/26
# かんにんぐ

n=int(input())
s=list(input())
cnt=float('inf')
bk=0
wh=s.count('.')
for i in range(n):
	if s[i]=='#':bk+=1
	else:wh-=1
	cnt=min(cnt,bk+wh)

print(cnt)

Submission status: Wrong Answer

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

mi = S.count(".")
c = N
for i in range(1,N-1):
    c = S[:i].count("#") + S[i:].count(".")
    mi = min(mi,c)

mi = min(mi,S.count("#"))

print(mi)

Submission status: Wrong Answer

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

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

for i in range(N):
    if S[i] == "#":
        print(min(S.count("."),S[:N-1].count("#")))
        exit()

Submission status: Wrong Answer

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

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

for i in range(N):
    if S[i] == "#":
        print(min(S[i+1:].count("."),S[:N-1].count("#")))
        exit()

Submission status: Wrong Answer

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

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

for i in range(N):
    if S[i] == "#":
        print(S[i+1:].count("."))
        exit()

Submission status: Wrong Answer

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

num = S[:-1].count("#")

if num >= N - 1 - num :
    if S[N-1] == "#":
        print(N - 1 - num)
    else:
        print(N-num)
else:
    print(num)

Submission status: Wrong Answer

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

num = S[:-1].count("#")

if num >= N - 1 - num :
    if S[N-1] == "#":
        print(N - 1 - num)
    else:
        print(N-num)
else:
    if S[N-1] == ".":
        print(num)
    else:
        print(num+1)

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(input())
if ar.count("#") == 0 or ar.count(".") == 0:
    print(0)
else:
    i = -1
    while True:
        if ar[i] == ".":
            break
        else:
            i -= 1
    if i == -1:
        br = ar
    else:
        br = ar[0:i+1]
    print(min(br.count("#"),br.count(".")))

Submission status: Wrong Answer

Solution code:
# 2019/07/26

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

Submission status: Wrong Answer

Solution code:
# 2019/07/26

n=int(input())
s=input()
a=s.count('.')
b=s.count('#')
print(min(a,b))

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(input())
wh = ar.count(".")
bl = ar.count("#")
if wh == 0 or bl == 0:
    print(0)
else:
    print(min(wh,bl))

Submission status: Wrong Answer

Solution code:
num = int(input())
line = list(input())
kaisu = 0
for n in range(num - 1):
  if line[n] == "#" and line[n + 1] == ".":
    kaisu += 1
print(kaisu)

Submission status: Wrong Answer

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

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

ans = 0
for i in range(N):
    if S[i] != T[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

W = [0] * N
W[-1] += S[-1] == "."
for i in range(N - 2, -1, -1):
    W[i] = W[i + 1] + (S[i] == ".")

B = [0] * N
B[0] += S[0] == "#"
for i in range(1, N):
    B[i] = B[i - 1] + (S[i] == "#")

T = [w + b for w, b in zip(W, B)]
T = min(T)
print(min(T, W[0], B[-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
flag = 0
for i in range(N):
    if S[i]=="#":
        flag = 1
        print(S[i:N].count("."))
        break
if flag == 0:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = 10 ** 10
for i in range(n):
  ss = s[:i]
  sss = s[i:]
  ans = min(ans,ss.count("#")+sss.count("."))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(str(input()))
b=n
w=0
if "." in l:w=n-1-l[::-1].index(".")
if "#" in l:b=l.index("#")
ans=min(l[b:].count("."),l[:w].count("#"))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(str(input()))
b=n
if "#" in l:b=l.index("#")
print(l[b:].count("."))

Submission status: Wrong Answer

Solution code:
def solve(n, s):
    l = 0
    r = n-1
    while l < n:
        if s[l] == "#":
            break
        l += 1
    while 0 <= r:
        if s[r] == ".":
            break
        r -= 1
    t = s[l:r+1]
    return min(t.count("."), t.count("#"))

assert solve(3, "#.#") == 1
assert solve(5, "#.##.") == 2
assert solve(9, ".........") == 0

n = int(input())
s = input()
print(solve(n, s))

Submission status: Wrong Answer

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

for i in range(n):
    if s[i] == '#':
        is_white += 1
    else:
        is_white -= 1

print(min(ans, is_white))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 10 ** 9 + 10

for i in range(1, n+1):
    left = s[:i]
    right = s[i:]
    is_black = left.count('#')
    is_white = right.count('.')
    if is_black + is_white < ans:
        ans = is_black + is_white

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count = 0
black = False

for i in range(n):
    if s[i] == '#':
        black = True
    elif s[i] == '.' and black == True:
        count += 1

print(count)

Submission status: Wrong Answer

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

for i in range(n):
  if s[i] == "#":
    ans = s[i:]
    print(ans.count("."))
    break
  elif i == n-1:
    print(0)

Submission status: Wrong Answer

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

for i in range(n):
  if s[i] == "#":
    ans = s[i:]
    print(ans.count("."))
    break

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# 最終形態は...か###か....####
# 一つでも #. のセットがある場合はいっそ.か#をぜんぶ入れ替えるほうがいいかどうかっていう
n, s = int(input()), input()
flag = True
for i in range(1, n):
    if s[i - 1] == "#" and s[i] == ".":
        flag = False
        break
if flag:
    print(0)
else:
    b = len(list(filter(lambda x: x == "#", s)))
    # 後ろの部分は黒関係ない
    countb = 0
    for bi in s[::-1]:
        if bi == "#":
            countb += 1
        else:
            break
    w = n - b
    countw = 0
    # 前の部分は白関係ない
    for wi in s:
        if wi == ".":
            countw += 1
        else:
            break
    print(min(w-countw, b-countb))

Submission status: Wrong Answer

Solution code:
# 最終形態は...か###か....####
# 一つでも #. のセットがある場合はいっそ.か#をぜんぶ入れ替えるほうがいいかどうかっていう
n, s = int(input()), input()
flag = True
for i in range(1, n):
    if s[i - 1] == "#" and s[i] == ".":
        flag = False
        break
if flag:
    print(0)
else:
    b = len(list(filter(lambda x: x == "#", s)))
    # 後ろの部分は関係ない
    count = 0
    for bi in s[::-1]:
        if bi == "#":
            count += 1
        else:
            break
    w = n - b
    print(min(w, b-count))

Submission status: Wrong Answer

Solution code:
# 最終形態は...か###か....####
# 一つでも #. のセットがある場合はいっそ.か#をぜんぶ入れ替えるほうがいいかどうかっていう
n, s = int(input()), input()
flag = True
for i in range(1, n):
    if s[i - 1] == "#" and s[i] == ".":
        flag = False
        break
if flag:
    print(0)
else:
    b = len(list(filter(lambda x: x == "#", s)))
    w = n - b
    print(min(w, b))

Submission status: Wrong Answer

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


ini_w = 0
for i in range(len(S)):
    if S[i] == '.':
        ini_w = ini_w + 1
    else:
        break
    
if ini_w >= len(S)-1:
    print(0)
    exit()
    
S = S[ini_w:]

all_w = len(S) - S.count(".")
all_b = len(S) - all_w

other = 2*10000000

last_b = 0

for i in range(len(S)):
    if S[len(S)-i-1] == '#':
        last_b = last_b + 1
    else:
        break

other = all_w - last_b
#print(other,last_b)
print(min(all_w,all_b,other))

Submission status: Wrong Answer

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

if "." not in s or "#" not in s:
    print(0)
else:
    ans = len(s)

    s = s[s.find("#"):n-s[::-1].find(".")]
    cnt_b = [0 for i in range(len(s))]
    cnt = 0
    for i in range(len(s)):
        if s[i] == "#":
            cnt += 1
        cnt_b[i] = cnt
    for i in range(len(s)):
        ans = min(ans, cnt_b[i] + (len(s)-cnt_b[-1])-(i+1-cnt_b[i]))
    print(ans)

Submission status: Wrong Answer

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

if "." not in s or "#" not in s:
    print(0)
else:
    ans = len(s)
    s = s[s.find("#"):n-s[::-1].find(".")]
    for i in range(len(s)):
        ans = min(ans, s[:i+1].count("#") + s[i+1:].count("."))
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s_rev = s[::-1]
idx = s.find("#")
if "." not in s or "#" not in s:
    print(0)
else:
    print(min(s[idx+1:].count('.'), s[idx:].count("#")-s_rev.find(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
idx = s.find("#")
print(min(s[idx+1:].count('.'), s[idx:].count("#")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()+"#"

cnt_w = 0
cnt_b = 0
cnt = 0
status = 0
for i in range(n+1):
    if status == 0:
        if s[i] == "#":
            cnt_b = 1
            status = 1
    elif status == 1:
        if s[i] == ".":
            cnt_w += 1
            status = 2
        else:
            cnt_b += 1
    elif status == 2:
        if s[i] == ".":
            cnt_w += 1
        else:
            cnt += min(cnt_b, cnt_w)
            cnt_b = 1
            cnt_w = 0
            status = 1

print(cnt)

Submission status: Wrong Answer

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

flag = False
cnt_w = 0
cnt_b = 0
for i in range(n):
    if s[i] == ".":
        if not flag:
            continue
        else:
            cnt_w += 1
    else:
        flag = True
        cnt_b += 1

print(min(cnt_w, cnt_b))

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:
n = int(input())
S = [s for s in input()]
w,b = [0],[0]
for i in range(n):
    if S[i] is '#': w.append(w[i]+1)
    else:   w.append(w[i])
    if S[n-i-1] is '.': b.append(b[i]+1)
    else:   b.append(b[i])
b = b[::-1]
#print(w,b)
ans = float('inf')
for i in range(1,n+1):
    ans = min(ans, w[i]+b[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [s for s in input()]
ans = 0
try:
    #print(S.index('#'))
    for i in range(S.index('#')+1,n):
        if S[i] is '.':
            ans += 1
    print(min(ans,S.count('#')))
except:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [s for s in input()]
ans = 0
try:
    #print(S.index('#'))
    for i in range(S.index('#')+1,n):
        if S[i] is '.':
            ans += 1
    print(ans)
except:
    print(0)

Submission status: Wrong Answer

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

idx_black = s.find(".")

if s.count(".") == 0 or s.count("#") == 0:
    print("0")
else:
    change_black = s[idx_black:].count(".")

    tail_black = s[::-1].find(".")
    change_white = s[idx_black - 1:].count("#") - tail_black

    print(min(change_black, change_white))

Submission status: Wrong Answer

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

idx_black = s.find(".")

change_black = s[idx_black:].count(".")
change_white = s[idx_black - 1:].count("#")

print(min(change_black, change_white))

Submission status: Wrong Answer

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

idx_black = s.find(".")

change_black = s[idx_black:].count(".")
change_white = s[idx_black:].count("#")

print(min(change_black, change_white))

Submission status: Wrong Answer

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

ans = N+1
prev = ""


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

first_white = white
first_black = N - first_white

for i in range(N):
    current = S[i]

    if prev is "#" and current is ".":

        ans = min(ans, black+white)

    if current is ".":
        white -= 1
    elif current is "#":
        black += 1

    prev = current

if ans == N + 1:
    ans = 0

print(min(ans, first_black, first_white))

Submission status: Wrong Answer

Solution code:

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

ans = N+1
prev = ""


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

first_white = white
first_black = N - first_white

for i in range(N):
    current = S[i]

    if prev is "#" and current is ".":

        ans = min(N, black+white)

    if current is ".":
        white -= 1
    elif current is "#":
        black += 1

    prev = current

if ans == N + 1:
    ans = 0

print(min(ans, first_black, first_white))

Submission status: Wrong Answer

Solution code:

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

ans = N+1
prev = ""


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

first_white = white
first_black = N - first_white

for i in range(N):
    current = S[i]

    if prev is "." and current is "#":

        ans = min(N, black+white)

    if current is ".":
        white -= 1
    elif current is "#":
        black += 1

    prev = current

if ans == N + 1:
    ans = 0

print(min(ans, first_black, first_white))

Submission status: Wrong Answer

Solution code:

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

ans = N+1
prev = ""

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

for i in range(N):
    current = S[i]

    if prev is "." and current is "#":

        ans = min(N, black+white)

    if current is ".":
        white -= 1
    elif current is "#":
        black += 1

    prev = current

if ans == N + 1:
    ans = 0

print(ans)