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

cumsum_b = [0] * N
cumsum_w = [0] * N

cum_b = 0
cum_w = 0
for i in range(N):#累積和
  if S[i] == "#":
    cum_b += 1
  else:
    cum_w += 1
  cumsum_b[i] = cum_b
  cumsum_w[i] = cum_w

ans = N
tmp = 0
if "#" not in S:
  print(0)
elif "." not in S:
  print(0)
else:
  for i in range(N):#白の範囲を全探索
    tmp = cumsum_b[i] + (cumsum_w[-1] - cumsum_w[i])
    if tmp < ans:
      ans = tmp
  else:
    print(ans)

Submission status: Wrong Answer

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

cumsum_b = [0] * N

cum = 0
for i in range(N):#累積和
  if S[i] == "#":
    cum += 1
  cumsum_b[i] = cum

ans = N
tmp = 0

if "#" not in S:
  print(0)
elif "." not in S:
  print(0)
else:
  for i in range(N):#白の範囲を全探索
    tmp = cumsum_b[i] + ((N-(i+1)) - (cumsum_b[-1] - cumsum_b[i]))
    if tmp < ans:
      ans = tmp
  else:
    print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=list(input())
white_stone=b.count(".")
black_stone=b.count("#")
if "#" in b:
    if "." in b:
        left_black=b.index("#")
        #print(left_black)
        left=b[left_black:]
        #print(left)
        b.reverse()
        #print(b)
        right_white=b.index(".")
        #print(right_white)
        right=b[right_white:]
        #print(right)
        #print(min([left.count("."),right.count("#"),len(b)//2]))
        print(min([left.count("."),right.count("#")]))
    else:
        print(min(white_stone,black_stone))
else:
    print(min(white_stone,black_stone))
# 最初の方のテストケースで失敗する

Submission status: Wrong Answer

Solution code:
a=int(input())
b=list(input())
white_stone=b.count(".")
black_stone=b.count("#")
if "#" in b:
    if "." in b:
        left_black=b.index("#")
        #print(left_black)
        left=b[left_black:]
        #print(left)
        b.reverse()
        #print(b)
        right_white=b.index(".")
        #print(right_white)
        right=b[right_white:]
        #print(right)
        print(min([left.count("."),right.count("#"),len(b)//2]))
    else:
        print(min(white_stone,black_stone))
else:
    print(min(white_stone,black_stone))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = [0]
check = s[0]
for i in range(len(s)):
    if check == s[i]:
        a[len(a)-1]+=1
    else:
        a.append(1)
        if check == ".": check = "#"
        else: check = "."
if s[0] == ".": del a[0]
if s[len(s)-1] == "#": del a[len(a)-1]



sum1 = 0
sum2 = 0
for i in range(0, len(a), 2):
    sum1+=a[i]
for i in range(1, len(a), 2):
    sum2+=a[i]
print (min(sum1,sum2))

Submission status: Wrong Answer

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

cnt=0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
print(min(S.count('.'), S.count('#')))

Submission status: Wrong Answer

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

# #を検出してその右にある全ての.をシャープに変える。最も左側にあるシャープを見つけてそれより右にある.の個数を返す

def first(S):
    if "#" in set(S):
        ichi=S.index("#")
        return int(S.count(".",ichi,int(N)))
    else:
        return 0

# .を検出してその左にある＃を.に変える。最も右にある.を見つけてそれより左にある#を数える。
def second(S):
    if "." in set(S):
        ichi =S.rindex(".")
        return int(S.count("#",0,ichi))
    else:
        return 0
print(min([first(S),second(S)]))

Submission status: Wrong Answer

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

# #を検出してその右にある全ての.をシャープに変える。最も左側にあるシャープを見つけてそれより右にある.の個数を返す

def first(S):
    if "#" in S:
        ichi=S.index("#")
        return int(S.count(".",ichi+1,int(N)))
    else:
        return 0

# .を検出してその左にある＃を.に変える。最も右にある.を見つけてそれより左にある#を数える。
def second(S):
    if "." in S:
        ichi =S.rindex(".")
        return int(S.count("#",0,ichi-1))
    else:
        return 0
print(min([first(S),second(S)]))

Submission status: Wrong Answer

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

# #を検出してその右にある全ての.をシャープに変える。最も左側にあるシャープを見つけてそれより右にある.の個数を返す

def first(S):
    if "#" in S:
        ichi=S.index("#")
        return int(S.count(".",ichi,int(N)))
    else:
        return 0

# .を検出してその左にある＃を.に変える。最も右にある.を見つけてそれより左にある#を数える。
def second(S):
    if "." in S:
        ichi =S.rindex(".")
        return int(S.count("#",0,ichi))
    else:
        return 0
print(min([first(S),second(S)]))

Submission status: Wrong Answer

Solution code:
N=input()
S=input()
 
# #を検出してその右にある全ての.をシャープに変える。最も左側にあるシャープを見つけてそれより右にある.の個数を返す
 
def first(S):
    if "#" in S:
        ichi=S.index("#")
        return int(S.count(".",ichi))
    else:
        return 0
 
# .を検出してその左にある＃を.に変える。最も右にある.を見つけてそれより左にある#を数える。
def second(S):
    if "." in S:
        ichi =S.rindex(".")
        return int(S.count("#",0,ichi))
    else:
        return 0
print(max([first(S),second(S)]))

Submission status: Wrong Answer

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

# #を検出してその右にある全ての.をシャープに変える。最も左側にあるシャープを見つけてそれより右にある.の個数を返す

def first(S):
    if "#" in S:
        ichi=S.index("#")
        return int(S.count(".",ichi))
    else:
        return 0

# .を検出してその左にある＃を.に変える。最も右にある.を見つけてそれより左にある#を数える。
def second(S):
    if "." in S:
        ichi =S.rindex(".")
        return int(S.count("#",0,ichi))
    else:
        return 0
print(max([first(S),second(S)]))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
 
white = s.count(".")
black = n - white
w_c = 0
b_c = 0
ans = n
if black and white:
  for i in range(n):
    if s[i] == ".":
      w_c += 1
    else:
      b_c += 1
    if b_c  + (white - w_c) < ans:
      ans = b_c  + (white - w_c) 
  print(ans)
print(0)

Submission status: Wrong Answer

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

white = s.count(".")
black = n - white
w_c = 0
b_c = 0
ans = n
for i in range(n):
  if s[i] == ".":
    w_c += 1
  else:
    b_c += 1
  if b_c  + (white - w_c) < ans:
    ans = b_c  + (white - w_c) 
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())

S=input()

A = [0]
a=0
for i in range(N):
    if S[i]=="#":
        a+=1
    A.append(a)
min_score=N

for i in range(N+1):
    min_score=min((N-i-(A[N]-A[i]))+(i-A[i]),min_score)
print(min_score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input().strip()
r = s.find('#')
p = s[:r] + "#"*(n-r)
q = "."*n
k = "#"*n

a = sum(s[i] != p[i] for i in range(n))
b = sum(s[i] != q[i] for i in range(n))
c = sum(s[i] != k[i] for i in range(n))
print(min(a, b, c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input().strip()
r = s.find('#')
p = s[:r] + "#"*(n-r)
q = "."*n

a = sum(s[i] != p[i] for i in range(n))
b = sum(s[i] != q[i] for i in range(n))
print(min(a, b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())[::-1]
white = False
cnt = 0
for i in range(n):
    if s[i] == ".":
        white = True
    elif white:
        cnt += 1
black = False
s = s[::-1]
cnt2 = 0
for i in range(n):
    if s[i] == "#":
        black = True
    elif black:
        cnt2 += 1

print(min(cnt, cnt2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
s = S.copy()
S.pop(0)
s.pop(N - 1)
 
c = 0
for i in range(N - 1):
  if s[i] == "#" and S[i] == ".":
    S[i] = "#"
    c += 1
    if s[i] == s[N-2]:
      pass
    else:
      s[i+1] = "#"
  else:
    pass
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
s = S.copy()
S.pop(0)
s.pop(N - 1)
 
c = 0
for i in range(N - 1):
  if s[i] == "#" and S[i] == ".":
    S[i] = "#"
    c += 1
  else:
    pass
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
s = S.copy()
S.pop(0)
s.pop(N - 1)
 
c = 0
for i in range(N - 1):
  if s[i] == "#" and S[i] == ".":
    c += 1
  else:
    pass
print(c)

Submission status: Wrong Answer

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

D = []
for i in range(N):
  if S[i] == '.':
    D.append(0)
  else:
    D.append(1)
    
cnt = 0
for i in range(N-2):
  p = N - 1 - i
  a = D[p-1]
  b = D[p]

  if ( a == 0) and ( b == 1):
    cnt += 1
    D[p-1] = 1

print(cnt)

Submission status: Wrong Answer

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

D = []
for i in range(N):
  if S[i] == '.':
    D.append(0)
  else:
    D.append(1)


cnt = 0
for i in range(N-1):
  p = N - 1 - i
  a = D[p-1]
  b = D[p]
  if ( a == 0) and ( b == 1):
    cnt += 1
    D[p-1] = 1
print(cnt)

Submission status: Wrong Answer

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


if "#." in s:
    idx = s.index("#")
    idx2 = len(s)- s[::-1].index(".")
    v = s[idx:idx2].count(".")
    w = (len(s[idx:idx2])) - v
    print(min(v, w))
else:
    print(0)

Submission status: Wrong Answer

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

cnt = 0
cnt_black = 0
first = 0
for x in S:
  if x == '#':
    cnt_black += 1
    cnt+=1
    first = 1
  else:
    first = 0
    cnt+=1
    
ret = 0
hit = 0
if (cnt == 0) or (cnt_black == cnt) or (cnt_black == 0):
  hit = 1
  
if (cnt -1 == cnt_black) and (first == 0):
  hit = 1
  
if hit == 0:
  ret = cnt - cnt_black
  
print(ret)

Submission status: Wrong Answer

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

if "#." in s:
    idx = s.index("#")
    idx2 = - s[::-1].index(".")
    v = s[idx:idx2].count(".")
    w = (len(s[idx:idx2])) - v
    print(min(v, w))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
s = S.count(".")
if S[0] == "#":
  print(s)
else:
  print(s-1)

Submission status: Wrong Answer

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

D = []
cnt = 0
cnt_black = 0
for x in S:
  if x == '#':
    D.append(1)
    cnt_black += 1
    cnt+=1
  else:
    D.append(0)
    cnt+=1
    
ret = 0
hit = 0
if (cnt == 0) or (cnt_black == cnt) or (cnt_black == 0):
  #print("ok")
  hit = 1
  
if (cnt -1 == cnt_black) and (D[0] == 0):
  #print("ok")
  hit = 1
  
if hit == 0:
  ret = cnt - cnt_black
  
print(ret)

Submission status: Wrong Answer

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

if "#" in s and "." in s:
    idx = s.index("#")
    idx2 = s[::-1].index(".") * -1
    v = s[idx:idx2].count(".")
    w = (len(s[idx:idx2])) - v
    print(min(v, w))
else:
    print(0)

Submission status: Wrong Answer

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

if "#" in s:
    idx = s.index("#")
    v = s[idx:].count(".")
    w = (len(s)-idx) - v
    print(min(v, w))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import numpy as np
import sys
""""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect
"""

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

"""
N = int(input())
S = input()
def main():
    B_list = []
    W_list = []
    BW_list = []
    for n in range(N):
        if S[n] == "#":
            B_list.append(n)
        else:
            W_list.append(n)
        if n > 0 and S[n] != S[n-1]:
            BW_list.append(n-1)
            
    if len(B_list) ==0 or len(W_list)==0:
        print(0)
        sys.exit()
    num_BL =np.inf
    num_WR =np.inf
    res = np.inf
    for i, n in enumerate(BW_list):
        num_BL = len(B_list[:find_index(BW_list, n)+1])
        num_WR = len(W_list[find_index(BW_list, n):])
        res = min(res, num_BL+num_WR)
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

"""
N = int(input())
S = input()
def main():
    B_list = []
    W_list = []
    BW_list = []
    for n in range(N):
        if S[n] == "#":
            B_list.append(n)
        else:
            W_list.append(n)
        if n > 0 and S[n] != S[n-1]:
            BW_list.append(n)
            
    if len(B_list) ==0 or len(W_list)==0:
        print(0)
        sys.exit()
    num_BL =np.inf
    num_WR =np.inf
    res = np.inf
    for i, n in enumerate(BW_list):
        num_BL = len(B_list[:find_index(BW_list, n)+1])
        num_WR = len(W_list[find_index(BW_list, n)+1:])
        res = min(res, num_BL+num_WR)
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a = S.count('.')
b = S.count('#')
c = '.#'
ans = min(a,b)

if c in S:
    print(ans - 1)
else:
    print(ans)

Submission status: Wrong Answer

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

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

print(min(a,b))

Submission status: Wrong Answer

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

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:
# _*_ coding: utf-8 _*_

n = int(input().strip())
s = input().strip()

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:
N = int(input())
S =(list(input()))
newS=[]
for i in S:
    if i == ".":
        newS.append(0)
    else:
        newS.append(1)

countW=newS.count(0)
countB=newS.count(1)
ans=min(countW,countB)
countB=0
for s in newS:
    if s ==1:
        
        countB+=1
    else:
      countW-=1
      
        
    ans=min(ans,countB+countW)
    print(countB,countW)
#print(ans)
print(ans)

Submission status: Wrong Answer

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

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

ar.append(prev)
if len(ar) > 0 and ar[-1].count('#') > 0:
    ar.pop(-1)
if len(ar) > 0 and ar[0].count('.') > 0:
    ar.pop(0)

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

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

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


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

Submission status: Wrong Answer

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

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

ar.append(prev)

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

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

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


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

Submission status: Wrong Answer

Solution code:
input()
s=input()
ct=0
for i in range(s.count(".")):
  if i == "#":
    ct+=1
print(ct*2)

Submission status: Wrong Answer

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

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

ar.append(prev)

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

if len(ar) > 0 and ar[-1].count('#') > 0:
    ar.pop(-1)
if len(ar) > 0 and ar[0].count('.') > 0:
    ar.pop(0)

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

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

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

Submission status: Wrong Answer

Solution code:
input()
s=input()
ct=0
for i in range(s.count("#")):
  if i == ".":
    ct+=1
print(ct*2)

Submission status: Wrong Answer

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

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

ar.append(prev)

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

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

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

"""
N = int(input())
S = input()
def main():
    B_list = []
    W_list = []
    BW_list = []
    for n in range(N):
        if S[n] == "#":
            B_list.append(n)
        else:
            W_list.append(n)
        if n > 0 and S[n] != S[n-1]:
            BW_list.append(n)
            
    if len(B_list) ==0 or len(W_list)==0:
        print(0)
        sys.exit()
    res = np.inf
    for n in BW_list:
        li_b= bisect.bisect_left(B_list, n)
        c1 = len(B_list[:li_b])
        li_w= bisect.bisect_left(W_list, n)
        c2 = len(W_list[li_w:])
        res = min(res, c1+c2)
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    buff = s[0]

    while_count = 0

    black_count = 0

    for stone in s:
        if buff == "#" and stone == ".":
            while_count += 1

        else:
            buff = stone

    buff = s[n-1]

    for stone in s[::-1]:
        if buff == "." and stone == "#":
            black_count += 1

        else:
            buff = stone

    print(min(while_count, black_count))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

"""
N = int(input())
S = input()
def main():
    B_list = []
    W_list = []
    BW_list = []
    for n in range(N):
        if S[n] == "#":
            B_list.append(n)
        else:
            W_list.append(n)
        if n > 0 and S[n] != S[n-1]:
            BW_list.append(n)
            
    if len(B_list) ==0 or len(W_list)==0:
        print(0)
        sys.exit()
    res = np.inf
    for n in BW_list:
        c1 = collections.Counter(S[:n+1])
        c2 = collections.Counter(S[n+1:])
        res = min(res, c1["#"]+c2["."])
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    buff = s[0]

    while_count = 0

    black_count = 0

    for stone in s:
        if buff == "#" and stone == ".":
            while_count += 1

        else:
            buff = stone

    buff = s[n-1]

    for stone in s[::-1]:
        if buff == "." and stone == "#":
            black_count += 1

        else:
            buff = stone

    black_stone = "".join(s).count("#")

    print(min(while_count, black_count, black_stone, n - black_stone))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(input())
c = 0
d = 0
e = []
st = a[N-1]
f = [st,1]
for i in range(2,N+1):
    if a[N-i] == st:
        f[1] += 1
    else:
        e.append(f)
        st = a[N-i]
        f = [st,1]
e.append(f)
for i in range(len(e) - 1):
    if e[i][0] == ".":
        c += e[i][1]
if e[len(e)-1][0] ==".":
    d += e[len(e)-1][1]
print(min(c,N-c-d))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

acc = [0]
acc2 = [0]
for s in S:
    if s == ".":
        acc.append(acc[-1] + 1)
        acc2.append(acc2[-1])
    else:
        acc.append(acc[-1])
        acc2.append(acc2[-1] + 1)
acc.pop(0)
acc2.pop(0)

ans = float("inf")

for i in range(N):
    s = S[i]
    tmp = acc[-1] - acc[i]
    tmp2 = acc2[i]
    ans = min(ans , tmp + tmp2)
print(ans)

Submission status: Wrong Answer

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

a = [(0, 0) for _ in range(len(s) + 1)]

i = 0
while i < len(s):
    bs, ws = a[i + 1]
    b0, w0 = a[i]

    if s[i] == '#':
        bs += 1
    else:
        ws += 1

    a[i + 1] = (bs + b0, ws + w0)
    i += 1


i = 0
can = len(s)
while i < len(s):
    can = min(can, a[i][0] + a[-1][1] - a[i][1])
    i += 1

print(can)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
s = [int(i=='#') for i in input()]

ans = []
blacks = 0
whites = np.sum(np.array(s)==0)

for x in s:
  if x==1:
    blacks += 1
  else:
    whites -= 1

  ans.append(blacks + whites)

print(np.min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
# N = int(input())
# stones = np.array([0 if stone == "." else 1 for stone in input()])
stones = np.array([0 if stone == "." else 1 for stone in "#.#"])


def count_painted_stones_by_cumsum(stones, length):
    left_black_stones = np.roll(np.cumsum(stones), 1)
    left_black_stones[0] = 0
    right_white_stones = np.roll(np.cumsum(1 - stones[::-1]), 1)
    right_white_stones[0] = 0

    return np.min(left_black_stones + right_white_stones[::-1])


# def count_painted_stones(stones, length):
#     repainted_times = []
#     for i in range(length+1):
#         left_stones = stones[:i]
#         # left_black_stones = left_stones.count("#")
#         left_black_stones = np.sum(left_black_stones)
#         right_stones = stones[i:]
#         # right_white_stones = right_stones.count(".")
#         right_white_stones = np.sum(1 - right_white_stones)
#         repainted_stones = left_black_stones + right_white_stones
#         repainted_times.append(repainted_stones)

#     return min(repainted_times)


print(count_painted_stones_by_cumsum(stones, len(stones)))