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 = list(input())
p = 0
cnt_b = 0
cnt_w = 0
total = 0
while p < len(S):
    p += 1
    if S[p-1] == '#':
        cnt_b += 1
        if len(S) <= p:
            break
        elif S[p] == '.':
            while S[p] == '.':
                cnt_w += 1
                p += 1
                if len(S) <= p:
                    if cnt_b > cnt_w:
                        total += cnt_w
                    elif cnt_b < cnt_w:
                        total += cnt_b
                    else:
                        total += cnt_b
                    break
                elif S[p] == '#':
                    if cnt_b > cnt_w:
                        total += cnt_w
                    elif cnt_b < cnt_w:
                        total += cnt_b
                    else:
                        total += cnt_b
                    cnt_b = 0
                    cnt_w = 0
print(total)

Submission status: Wrong Answer

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

s = S
first_sharp = s.find('#')
if first_sharp == -1:
    print(0)
else:
    s = s[first_sharp:]

    ans = 2 * 10 ** 5
    for i in range(len(s)):
        #print(S[:i], S[i:])
        sharp_num = s[i:].count('#') # 後ろを#→.
        dot_num = s[:i].count('.') # 前を . → #
        ans = min(ans, dot_num + sharp_num)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt1 = 0
S1 = S
judge = False
for i in range(1, N):
  if cnt1 == S.count("#") or S.count("."):
    break
  for j in range(1, N):
    if S1[j-1] == "#" and S1[j] == ".":
      if S.count("#") > S.count("."):
        S1 = S1.replace(S1[j-1], ".", 1)
      else:
        S1 = S1.replace(S1[j], "#", 1)
      cnt1 += 1
print(min(cnt1,S.count("#"), S.count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
flag = 0
ans1 = 0
ans2 = 0
for x in s:
    if x == '#':
        flag = 1
        ans1 += 1
    elif x == '.' and flag == 1:
        ans2 += 1
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = [0]*(n+1)
count = 0
for i in range(len(s)) :
    if s[i] == "." :
        count += 1
    l[i+1] = count
siro = l[-1]
ans = 1000000000000000000000
for i in range(1,n+1):
    ans = min(ans,i-2*l[i]+siro)
if siro == 0 :
    print(0)
else:
    print(ans)
"""
  1 2 3 4 5 6 7 8
 . # . . # # . #
0 1 1 2 3 3 3 4 4
"""
"""
  1 2 3 4
 . # # .
0 1 1 1 2
"""

Submission status: Wrong Answer

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

count = 0
ans = 0
revcount = 0
for i in range(N-1,-1,-1):
    if S[i] == ".":
        count+=1
        #revcount = 0
    else:
        revcount+=1
        ans+=count
        count=0
p = 0
for i in range(N-1,-1,-1):
    p+=1
    if S[i] == ".":
        break
    
#print(revcount,ans,N-p)
print(min(revcount,ans,S[:N-p].count("#")))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
k = -1
tmp=0
for n,i in enumerate(S):
    if i=="#":
        k = n
        break
for i in S[::-1]:
    if i=="#":
        tmp-=1
    else:
        break

if k==-1:
    print(0)
else:
    if tmp!=0:
        SS = S[k:tmp]
    else:
        SS = S[k:]
    t =  sum([1 if i=="." else 0 for i in SS])
    print(min(t,len(SS)-t))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
S = input().strip()
S = S.rstrip("#")
S = S.lstrip(".")
print(min(S.count("#"), S.count(".")))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
S = list(str(input()))
 
#print(N,S)
 
box = []
a = 1
for i in range(N-1):
    #print(S[i],S[i+1])
    if S[i] == "#" and S[i+1] == "." or S[i] == "." and S[i+1] == "#":
        box.append(a)
        a = 1
        
        
    else:
        a += 1
        
    if i == N-2:
            box.append(a)    
 
#print(box)

BLACK = 0
WHITE = 0
START = 0
STOP = len(box)

if S[0] == ".":
    START = 1
    
if S[N-1] == "#":
    STOP = len(box)-1
    
for i in range(START,STOP):
    if i % 2 == 1:
        BLACK += box[i]
    else:
        WHITE += box[i]

print(min(BLACK,WHITE))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

    
change=0
s = list(s_0)

#blackのが多い
for i in range(1,n):
  if s[i-1]=="#" and s[i]==".":
    change=change+1
    s[i]="#"


#白のが多い
if change > n - change:
  change=n-change
  if s[n-1]=="#":
    change=change-1

print(change)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = list('##.#')
b = list('##..')
c = list('.#.#')
d = list('.#..')
ans = 0

if N <= 3:
    if S.find('#.') != -1:
        print(1)
    else:
        print(0)
else:
    S = '.' + S
    S = S + '#'
    t = list(S[:4])
    e = 3
    N += 2
    while True:
        if t == a or t == b or t == c:
            ans += 1
            t[2] = '#'
        elif t == d:
            ans += 1
            t[1] = '.'
        e += 1
        if e > N-1:
            break
        t = t[1:] + [S[e]]
    print(ans)

Submission status: Wrong Answer

Solution code:
# n=int(input())
# s=list(input())
# s2=s[:]
# s2.reverse()
# c=0
# for i in range(len(s)):
#   a=s[i]
#   if a=='#':
#     if i!=len(s)-1 and s[i+1]=='.':
#       s[i+1]='#'
#       c+=1
# c2=0
# for i in range(len(s2)):
#   a=s2[i]
#   if a=='.':
#     if i!=len(s2)-1 and s2[i+1]=='#':
#       s2[i+1]='.'
#       c2+=1
# print(s,s2)
# print(min(c,c2))

n=int(input())
s=list(input())
l=[]
a=s[0]
b=a
c=1
for x in s[1:]+['a']:
  if a==x:
    c+=1
  else:
    a=x
    l.append(c)
    c=1

l1=[]
l2=[]
a1=b1=0
f=0
for x in l:
  if f==0:
    a1+=x
    f=1
    l1.append(a1)
  else:
    b1+=x
    f=0
    l2.append(b1)
# print(l1,l2)
mn=1000000
if b=='.':
  l1=[0]+l1
  if len(l1)-1==len(l2):
    l2=[0]+l2
  else:
    l2=[0,0]+l2
  for i in range(len(l1)):
    # print(l1[-1]-l1[i]+l2[i])
    mn=min(l1[-1]-l1[i]+l2[i],mn)
  print(mn)
else:
  l1=[0]+l1
  if len(l1)-1==len(l2):
    l2=[0]+l2
  else:
    l2=[0,0]+l2
  for i in range(len(l2)):
    # print(l1[-1]-l1[i]+l2[i])
    mn=min(l1[-1]-l1[i]+l2[i],mn)
  print(mn)

# if b=='#':
#   for i in range(len(l)//2):
#     cx+=(min(l[2*i],l[2*i+1]))
# else:
#   l2=l[1:]+[0]
#   for i in range(len(l2)//2):
#     cx+=(min(l2[2*i],l2[2*i+1]))
# print(cx)

Submission status: Wrong Answer

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

a = s.count('#')
b = s.count('.')

print(min(a,b))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

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

ans = n
if s.count('#') == n or s.count('.') == n:
    ans = 0
    print(ans)
else:
    for i in range(n):
        num = s[:i].count('#') + s[i:].count('.')
        if num < ans:
            ans = num
        else:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:

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


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

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

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

print(min(w_b,allb,allw))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
xx = []
ten = []
count = 0#最初
count1 = 0 
count2 = 1
count3 = 0
count4 = 0
count5 = 0
for i in S:
    if i=="#" and count==0:
        count1 += 1
        count = 1
       
    elif i =="#" and count2==1 and count==1:
        count1 += 1
        
    elif i =="." and count2==1 and count==1:
        xx.append(count1)
        count1 = 1
        count2 = 0
        
    elif i =="." and count2==0 and count==1:
        count1 += 1

    elif i=="#" and count2==0 and count==1:
        ten.append(count1)
        count1 = 1
        count2 = 1


if count2==0 and count1>=1:
    ten.append(count1)

for i in range(len(xx)):
    if (xx[i]+count5)>=ten[i]:
        count3 += ten[i]
        count5 += ten[i]+xx[i]
    else:
        count3 += xx[i]
        count5 = 0
count4 = sum(xx)
if count3 > count4:
    count3 = count4
        
print(count3)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt_b = 0
cnt_w = 0
Is_Black = False
ans = 0

# ans = S.count("#.")
# print(ans)

for i in range(N):
    if S[i] == "#":
        if Is_Black:
            if cnt_w == 0:
                cnt_b += 1
            elif cnt_b != 0 and cnt_w != 0:
                ans += min(cnt_b, cnt_w)
                cnt_b = 1
                cnt_w = 0
        else:
            Is_Black = True
            cnt_b += 1
    else:
        if Is_Black and cnt_b!=0:
            cnt_w += 1
else:
    if cnt_b != 0 and cnt_w != 0:
                ans += min(cnt_b, cnt_w)
                cnt_b = 1
                cnt_w = 0

print(ans)

Submission status: Wrong Answer

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

# #-.-#-.の形式で集計する
count=0
now="#"
num_list=[]
for c in s_input:
    if c == now:
        count+=1
    else:
        num_list.append(count)
        count=1
        now="#" if now=="." else "."
num_list.append(count)

# 最後が0のグループだと都合が悪い
if len(num_list)%2==1:
    num_list.append(0)

count=0
for i in range(0,len(num_list),2):
    count+=min(num_list[i],num_list[i+1])

print(count)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

N = int(input())
S = str(input())
Sarray = list(S)
Sarraynum = []
d = []
for i in range(len(Sarray)):
    if Sarray[i] == '.':
        d.append(i)
e = []
f = len(Sarray)
g = 0
for i in range(1,len(d)):
    e.append(d[i] - d[i-1])
    if e[i - 1] <= f:
        f = e[i - 1]
        g = i

b = 0
for j in range(0,g):
    if Sarray[j] == '#':
        b += 1
for j in range(g+1,len(Sarray)):
    if Sarray[j] == '.':
        b += 1
print(b)


'''
#白0

for i in range(len(Sarray)):
    if Sarray[i] == '.':
        Sarraynum.append(0)
    else:
        Sarraynum.append(1)

a = 0
for i in range(len(Sarraynum)):
    a += Sarraynum[i]
a = len(Sarraynum) - a
b = [a]

for i in range(len(Sarraynum)):
    if Sarraynum[i] == 0:
        b.append(b[i] - 1)
    elif Sarraynum[i] == 1:
        b.append

    if b < a:
        a = b

print(a)

print(a)
'''
'''
for i in range(len(Sarraynum)):
    b = 0
    jmax = len(Sarraynum) - i - 1
    if jmax < i:
        jmax = i
    c = int(len(Sarraynum) / 2)
    for j in range(c,jmax):
        if j <= i:
            b += Sarraynum[j]
        if i + 1 + j < len(Sarraynum):
            if Sarraynum[i + 1 + j] == 0:
                b += 1
        if b >= a:
            break

    for j in reversed(range(c)):
        if j <= i:
            b += Sarraynum[j]
        if i + 1 + j < len(Sarraynum):
            if Sarraynum[i + 1 + j] == 0:
                b += 1
        if b >= a:
            break
    
    if b < a:
        a = b

print(a)
'''

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10000000)


def check_and_back_or_go_to(li, ind, N, counter, white_charge, black_charge):
    back = True
    # print('see {} {} and {} counter{}'.format(ind, li[ind - 1], li[ind], counter))
    if ind == 0:
        return counter

    # access
    if li[ind - 1] == '#' and li[ind] == '.':
        # print('add')
        c = check_and_back_or_go_to(li, ind - 1, N, counter + 1, white_charge, black_charge)
        return c
    elif li[ind - 1] == '.' and li[ind] == '.':
        return check_and_back_or_go_to(li, ind - 1, N, counter, white_charge + 1, black_charge)

    elif li[ind - 1] == '#' and li[ind] == '#':
        return check_and_back_or_go_to(li, ind - 1, N, counter, white_charge , black_charge + 1)
    elif li[ind - 1] == '.' and li[ind] == '#':
        adder = min([white_charge, black_charge])
        # print('adder {} WP{}'.format(adder,white_charge))
        return check_and_back_or_go_to(li, ind - 1, N, counter + adder, 0, 0)
    else:
        c = check_and_back_or_go_to(li, ind - 1, N, counter, white_charge, black_charge)
        return c


N = int(input())
S = list(input())
r = range(N)
if N == 1:
    print(0)
    exit(0)
bsk = False
key = -1
for i in range(len(S)):
    if not bsk:
        if S[i] == '#':
            bsk = True
            key = i
    else:
        if S[i] != '#':
            bsk = False

if bsk and key == 0:
    print(0)
    exit(0)

if bsk:
    # print('bsk occured')
    # print([S[i] for i in range(key)])
    count = check_and_back_or_go_to([S[i] for i in range(key)], key - 1, N, 0, 0, 0)
    print(min([count, key - count]))
else:
    count = check_and_back_or_go_to(S, len(S) - 1, N, 0, 0, 0)
    print(min([count, N - count]))

Submission status: Wrong Answer

Solution code:


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

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

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

S += "q"

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

A = []
B = []

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

l = []
now = '.'
count = 0
for i in range(n):
  if ( s[i] != now ):
    l.append(count)
    now = s[i]
    count = 0
  count += 1

if ( count > 0 ):
  l.append(count)

l.append(0)

#print(l)

ans = 99999
left = 0
right = 0

for j in range(int((len(l)-1)/2)):
  right += l[(j+1)*2]

for ii in range(int(len(l)/2)):
  i = ii*2

  if( i!=0):
    right -= l[i]

  count = 0
  if ( i!=0):
    left += l[i-1]
  
  count = left + right
  #print(i, count, left, right)
  
  if (ans>count):
    ans = count

if (ans == 99999):
  ans = 0

print(ans)

Submission status: Wrong Answer

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

li = list(S)
count = 0

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

Submission status: Wrong Answer

Solution code:
from __future__ import print_function
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


n=int(input())
S=list(input())

cnt_temp=0
cnt_temp2=0
stack=[]
cnt=0

# # eprint(n)
# # eprint(S)

# for i in range(n):
#     # eprint(i)


flag=0
flag2=0
start=0

for i in range(n):
    if S[i] == '.':
        cnt_temp+=1



if S[0] == '.':
    flag =1
# eprint("flag: ",end="")
# eprint(flag)

if flag==1:
    cnt_temp=0
    for i in range(n-1):
        if S[i]=='#' and S[i+1]=='.':
            flag2=1
            for j in range(i+1,n):
                if S[j] =='.':
                    cnt_temp+=1
            break
# eprint("flag2: ",end="")
# eprint(flag2)
        

        
for _ in S:
    print( _ , end="")
print()
        
for i in range(n-1):
    if S[i]=='#' and S[i+1]=='#':
        stack.append(i)
    elif S[i]=='#' and S[i+1]=='.':
        
        S[i]='.'
        cnt+=1
        
        # for _ in S:
            # eprint(_,end="")
        # eprint()
        
        
        
        while stack!=[]:
            temp=stack.pop()
            S[temp]='.'
            cnt+=1
            # for _ in S:
                # eprint(_,end="")
            # eprint()

            
        
# eprint("cnt: ",end="")
# eprint(cnt)
# eprint("cnt_temp2: ",end="")
# eprint(cnt_temp2)

print(min(cnt,cnt_temp))
            #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #

Submission status: Wrong Answer

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

flag = False
countA = 0
countBtmp = 0
countB = 0
for i in range(N):
  if S[i] == '#':
    flag = True
    countBtmp = countBtmp + 1
  elif flag is True:
    countA = countA + 1
    countB = countBtmp

if countA < countB:
  print("countA")
else:
  print("countB")

Submission status: Wrong Answer

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

flag=0
for i in range(n):
  if s[i]=='#' and flag==0:
      val=i
      flag=1
s=s[val:]
print(s.count('.') if val > 0 else 0)

Submission status: Wrong Answer

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

sa = np.array([1 if i == "#" else 0 for i in S])
num = np.arange(N)
num_w = num[sa==0]
num_b = num[sa==1]
if len(num_b) == 0 or len(num_w) == 0:
    print(0)
    import sys
    sys.exit()
kb = 0
kw = 0
if num_b[-1] == N-1:
    num_b2 = num_b[num_b < num_w[-1]]
    kb = 1
if num_w[0] == 0:
    num_w2 = num_w[num_w > num_b[0]]
    kw = 1
if kb == 1:
    num_b = num_b2
if kw == 1:
    num_w = num_w2
if len(num_b) > len(num_w):
    print(len(num_w))
else:
    print(len(num_b))

Submission status: Wrong Answer

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

# 白にする
# res1 = 0
# index1 = 0

res1 = 0
res2 = 0
index1 = 0
index2 = len(s) - 1
if s[0] == ".":
    for i in range(1, len(s)):
        if s[i] != s[i - 1]:
            index1 = i
            break
        index1 = len(s)
if s[-1] == "#":
    for i in range(len(s) - 1, 0, -1):
         if s[i] != s[i - 1]:
             index2 = i - 1
             break


for i in range(index1, index2 + 1):
    if s[i] == ".":
        res1 += 1
for i in range(index1, index2 + 1):
    if s[i] == "#":
        res2 += 1

print(min(res1, res2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
N = len(S)
MAX = 2 * (10 ** 5)

# . : white
# # : black
# no '#.' sequence

# a list that represents no of stones seen up to the index
nwhite, nblack = [], []

nwhite_current, nblack_current = 0, 0

for c in S:
    if c == '.':
        nwhite_current += 1
    else:
        nblack_current += 1

    nwhite.append(nwhite_current)
    nblack.append(nblack_current)

if nwhite_current == 0 or nblack_current == 0:
    print(0)

else:
    # indices of start of the sequence of black stones
    black = []
    flag = False

    for i, c in enumerate(S):
        if c == '#':
            if not flag:
                black.append(i)
                flag = True
        
        else:
            flag = False

    # print('white: ',nwhite)
    # print('black: ', nblack)
    # print('i-black: ',black)

    ans = MAX + 1

    # set a index that starts sequence of black(#)
    for i in black:

        curans = 0

        # then turn over all black(#) left to it
        if i > 0:
            curans = nblack[i-1]

        # then turn over all white(.) right to it    
        curans += (nwhite_current - nwhite[i])

        ans = min(ans, curans)

    print(ans)

Submission status: Wrong Answer

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

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

print(min(stones.count("#"), stones.count(".")))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N =  input()
S =  input()
t = "."
bef = 0
c = 0
ans = 0
for s in S[1:]:
  if  s != t:
    t = s
    ans += min(c, bef)
    bef = c
    c = 0
  else:
    c += 1

if(t == "."):
  ans += min(c, bef)
print(ans)

Submission status: Wrong Answer

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

zeros = ["." for i in range(N)]
ones = ["#" for i in range(N)]
two = ['#' for i in range(N - 1)]
two.insert(0, '.')
z = 0
o = 0
f = 0
two_count = 0
two_list = [0]
    

for i in range(N):
    if S[i] != zeros[i]:
        z += 1

for i in range(N):
    if S[i] != ones[i]:
        o += 1

for i in range(N):
    if S[i] != two:
        f += 1
                
for i in range(1, N - 1):
    two[i] = '.'
    for j in range(N):
        if S[j] != two[j]:
            two_count += 1
    two_list.append(two_count)
    two_count = 0

t = min(two_list)

minval = min([z, o, f, t])

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        # white
        L[i] = 1
    else:
        L[i] = 0
# L = np.array(L, dtype=np.int8)
L2 = np.zeros(N, dtype=np.int8)
# ans = np.abs((L - L2)).sum()
# for i in range(N):
#     L2[N-1-i] = 1
#     ans_tmp = np.abs((L - L2)).sum()
#     ans = min(ans, ans_tmp)
# print(ans)
all_whitedist = np.abs((L - L2)).sum()
dist = np.zeros(N, dtype=np.int8)
dist[0:] = all_whitedist
dist[0] = all_whitedist
for i in range(N):
    if L[N-1-i] == 1:
        dist[i:] -= 1
    else:
        dist[:i] -= 1
indx = np.where(dist == dist.min())[0][0]
L3 = np.zeros(N, dtype=np.int8)
L3[indx:] = 1
ans_tmp = np.abs((L - L3)).sum()
print(min(all_whitedist, ans_tmp))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
S = list(str(input()))
 
#print(N,S)
 
box = []
a = 1
for i in range(N-1):
    #print(S[i],S[i+1])
    if S[i] == "#" and S[i+1] == "." or S[i] == "." and S[i+1] == "#":
        box.append(a)
        a = 1
        
        
    else:
        a += 1
        
    if i == N-2:
            box.append(a)    
 
print(box)

BLACK = 0
WHITE = 0
START = 0
STOP = len(box)

if S[0] == ".":
    START = 1
    
if S[N-1] == "#":
    STOP = len(box)-1
    
for i in range(START,STOP):
    if i % 2 == 1:
        BLACK += box[i]
    else:
        WHITE += box[i]

print(min(BLACK,WHITE))

Submission status: Wrong Answer

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

for i in range(N):
    if S[i] == "#":
        memo = i
        break
        
print(S[memo:].count(".") if "#" in S else 0)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
dif = 0
ans_i = 0
mem = -100000000
for i, char in enumerate(S):
    if char == '.':
        dif += 1
    else:
        dif -= 1
    if dif > mem:
        mem = dif
        ans_i = i
print(S[:ans_i+1].count('#') + S[ans_i+1:].count('.'))

Submission status: Wrong Answer

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

left = stones.find("#")

if left == -1:
    print(0)
else:
    right = stones.rfind(".#")
    if right == -1:
        stonesToChange = stones[left:]
    else:
        stonesToChange = stones[left:right]


    print(min(stonesToChange.count("."), stonesToChange.count("#")))

Submission status: Wrong Answer

Solution code:
# n=int(input())
# s=list(input())
# s2=s[:]
# s2.reverse()
# c=0
# for i in range(len(s)):
#   a=s[i]
#   if a=='#':
#     if i!=len(s)-1 and s[i+1]=='.':
#       s[i+1]='#'
#       c+=1
# c2=0
# for i in range(len(s2)):
#   a=s2[i]
#   if a=='.':
#     if i!=len(s2)-1 and s2[i+1]=='#':
#       s2[i+1]='.'
#       c2+=1
# print(s,s2)
# print(min(c,c2))

n=int(input())
s=list(input())
l=[]
a=s[0]
b=a
c=1
for x in s[1:]+['a']:
  if a==x:
    c+=1
  else:
    a=x
    l.append(c)
    c=1

l1=[]
l2=[]
a1=b1=0
f=0
for x in l:
  if f==0:
    a1+=x
    f=1
    l1.append(a1)
  else:
    b1+=x
    f=0
    l2.append(b1)
# print(l1,l2)
mn=1000000
if b=='.':
  l1=[0]+l1
  l2=[0,0]+l2
  for i in range(len(l1)):
    # print(l1[-1]-l1[i]+l2[i])
    mn=min(l1[-1]-l1[i]+l2[i],mn)
  print(mn)
else:
  l1=[0]+l1
  if len(l1)-1==len(l2):
    l2=[0]+l2
  else:
    l2=[0]+l2
  for i in range(len(l2)):
    # print(l1[-1]-l1[i]+l2[i])
    mn=min(l1[-1]-l1[i]+l2[i],mn)
  print(mn)

# if b=='#':
#   for i in range(len(l)//2):
#     cx+=(min(l[2*i],l[2*i+1]))
# else:
#   l2=l[1:]+[0]
#   for i in range(len(l2)//2):
#     cx+=(min(l2[2*i],l2[2*i+1]))
# print(cx)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        #break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        #break

count=0
#print(dot)#左から
#print(sha)#右から
count_a=0
count_b=0
for i in range(N):
    if i<dot and S[i]!=".":
        count_a+=1
for i in range(N):
    if i<sha and s_r[i]!="#":
        count_b+=1
#print(count)

a=0
b=0

for i in range(N):
    if S[i]!=".":
        a+=1
    if S[i]!="#":
        b+=1

#print(count)
ans=min(count_a,count_b,a,b)
print(ans)

Submission status: Wrong Answer

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

# Parse and assignment for input
n = int(input())
s = input()

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=0
s.append('A')
if s[0]=='#':
    a=1
    while s[a]=='.' and a!=n:
        a+=1
        ans+=1
for i in range(1,n):
    if s[i]=='#' and i!=n:
        a=i+1
        while s[a]=='.' and a!=n:
            a+=1
            ans+=1
ans2=s.count('#')
print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
N=int(input())-1;S=input();f=[];flag=0;l=0;
for i in range(N):
 if S[i] == "#" and i != N:
  if S[i+1] == ".":
   while (1):
    if S[i-l] != "#":
     f.append(abs(l));l=0;break
    l+=1;
   while (1):
    if i+l != N:
     if S[i+l+1] != ".":
      f.append(l);l=0;break
     l+=1
    else:
     f.append(l);l=0;break
   flag += min(f);f=[];
print(flag)

Submission status: Wrong Answer

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

S = input()

count1 = 0
count2 = 0
ans = 0
for i in range(N):
    s = S[i]
    if s == '#':
        if i != 0 and S[i-1] == '.':
            if count1 > 0:
                ans += min(count1, count2)
            count2 = 0
            count1 = 0
        count1 += 1
    elif s == '.':
        count2 += 1
    
    if i == N-1 and s == '.':
        ans += min(count1, count2)

print(ans)