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

def method():
    _ = input()
    string = input()
    hasBlack = False
    count = 0
    count2 = 0
    for s in string:
        if s == "#":
            hasBlack = True
            count2 += 1
        elif hasBlack:
            count = count + 1
    print(min(count, count2))

method()

Submission status: Wrong Answer

Solution code:
n = int(input())
tip = []
cnt = 1
s = list(input())
ans = [s.count("#"), s.count(".")]
for i in range(1, n):
    if s[i] == s[i-1]:
        cnt += 1
    else:
        tip.append([s[i-1], cnt])
        cnt = 1
tip.append([s[-1], cnt])


if tip[-1][0] == "#":
    tmp = 0
    for i in range(len(tip) - 1):
        if tip[i][0] == "#":
            tmp += tip[i][1]
    ans.append(tmp)
print(min(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
a=0
try:
    m=0
    z=sorted([i for i, x in enumerate(S) if x == '#'],reverse=True)
    for i in S[::-1]:
        if i=="#":
            m+=1
        else:
            break
    if len(z)>1:
        z=(len(z)-m)
    else:
        z=len(z)
    c=0
    tmp=""
    c=S.index("#")
    b=S.index(".")
    print(min(S[c:].count("."),z))
except:
    print(0)

Submission status: Wrong Answer

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

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 = "...."


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

    return np.min(left_black_stones + right_white_stones)


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

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

        if stone == "#":
            black_count += 1

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def trim(s):
    i = 0
    while i < n and s[i] == '.':
        i += 1
    start = i

    i = n
    while i > 0 and s[i - 1] == '#':
        i -= 1
    end = i

    return s[start:end]


s = trim(s)
i = 0
bw = []

while i < len(s):
    bs = 0
    ws = 0
    while i < len(s):
        if s[i] == '#':
            bs += 1
            i += 1
        else:
            break
    while i < len(s):
        if s[i] == '.':
            ws += 1
            i += 1
        else:
            break

    bw.append(bs)
    bw.append(ws)


a = [0 for _ in range(len(bw) + 2)]

i = 2
while i < len(a):
    a[i] = a[i - 2] + bw[i - 2]
    a[i + 1] = a[i - 1] + bw[i - 1]
    i += 2

i = 2
can = len(s)

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

print(min(can, a[-1], a[-2]))

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 = []
    for n in range(N):
        if S[n] == "#":
            B_list.append(n)
        else:
            W_list.append(n)
    if len(B_list) ==0 or len(W_list)==0:
        print(0)
        sys.exit()
    cnt_b =0
    for i, b in enumerate(B_list):
        if i == 0:
            continue
        else:
            cnt_b += B_list[i]-B_list[i-1]-1
    if W_list[-1] > B_list[-1]:
        cnt_b += W_list[-1] - B_list[-1]
    
    cnt_w = 0
    for i, w in enumerate(W_list):
        if i == 0:
            continue
        else:
            cnt_w += W_list[i]-W_list[i-1]-1
    if W_list[0] > B_list[0]:
        cnt_w += W_list[0] - B_list[0]
    
    print(min(cnt_w, cnt_b))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding: utf-8

def method():
    _ = input()
    string = input()
    hasBlack = False
    count = 0
    for s in string:
        if s == "#":
            hasBlack = True
        elif hasBlack:
            count = count + 1
    print(count)

method()

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)

cnt = 0
if ar[-1].count('#') > 0:
    ar.pop(-1)
if len(ar) > 0 and ar[0].count('.') > 0:
    ar.pop(0)
while True:
    if len(ar) < 2:
        break
    last = ar[-1]
    last2 = ar[-2]
    if len(last2) >= len(last):
        cnt += len(last)
        ar.pop(-2)
        ar.pop(-1)
    else:
        break

new_s = ''.join(ar)

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

cnt += min(a,b)
print cnt

Submission status: Wrong Answer

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

m1=0
m2=0

for i in range(n):
  if s[i] == '#':
    m1+=1
  if s[i] == '.':
    m2+=1

m3=0
a=0
for i in range(n):
  if n-i-1 == a:
    break
  if s[n-i-1] == '.':
    flag=0
    for j in range(a,n):
      if j == n-i-1:
        break
      if s[j] == '#':
        if n-j -1 == m1:
          m3+=1
          break
        m3+=2
        a=j+1
        flag=1
        break
    if flag == 0:
      break

print(min(m1,m2,m3))

Submission status: Wrong Answer

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

length = []
cnt = 0
now = "#"
length_sum = []
length_num = 0
change = ""

ans = 0
for i in S:
  if now == i:
    cnt += 1
  else:
    if now == "#":
      now = "."
    else:
      now = "#"
    length.append(cnt)
    length_num += 1
    if length_num > 1 and length_num % 2 == 0:
        if length_num > 2:
            
            if change == "min":
                ans += min(length[length_num-2],length[-1])
            elif change == "#":
                ans += length[length_num-2]
            else:
                ans += length[-1]
                
        else:
            ans += min(length[length_num-2],length[-1])

            if length[length_num-2] == length[-1]:#==.
                change = "min"
            elif length[length_num-2] < length[-1]:#<.
                change = "#"
            else:#>.
                change = "."
            
    cnt = 1
else:
    length.append(cnt)
    length_num += 1
    if length_num > 1 and length_num % 2 == 0:
        if length_num > 2:
            
            if change == "min":
                ans += min(length[length_num-2],length[-1])
            elif change == "#":
                ans += length[length_num-2]
            else:
                ans += length[-1]
                
        else:
            ans += min(length[length_num-2],length[-1])

            if length[length_num-2] == length[-1]:#==.
                change = "min"
            elif length[length_num-2] < length[-1]:#<.
                change = "#"
            else:#>.
                change = "."

print(min(min(ans,sum(length[0::2])),sum(length[1::2])))

Submission status: Wrong Answer

Solution code:
n = int(input())
ss = input()
flag = True
ans =  0
i = 0
a = 0
black = ss.count('#')
for s in ss:
    if black >= n - black:
        if flag:
            if s == '#':
                flag = False
        else:
            if s == '.':
                ans += 1
    else:
        if s == '#':
            ans += 1
        i += 1
        if flag:
            if ss[n-i] == '.':
                a = i
                flag = False
print(ans-a)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
min = S[0:N].count('#')
for i in range(0, N):
    if min > S[0:i + 1].count('#') + S[i + 1:N].count('.'):
        min = S[0:i + 1].count('#') + S[i + 1:N].count('.')
print("{}".format(min))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
if all(S)=="#" or all(S)==".":
    print(0)
    exit
else:
    pass
for i in reversed(range(N)):
    if S[i]==".":
        if i==0:
            break
        else:
            for j in range(1,i+1):
                if S[i-j]=="#":
                    count+=1
                else:
                    break
    else:
        pass
if S[0]=="#":
    print(min(count,N-count))
else:
    print(min(count,N-count-1))

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)

cnt = 0
if len(ar) > 0 and ar[-1].count('#') > 0:
    ar.pop(-1)
if len(ar) > 0 and ar[0].count('.') > 0:
    ar.pop(0)
while True:
    if len(ar) < 2:
        break
    last = ar[-1]
    last2 = ar[-2]
    if len(last2) >= len(last):
        cnt += len(last)
        ar.pop(-2)
        ar.pop(-1)
    else:
        break

new_s = ''.join(ar)

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

cnt += min(a,b)
print cnt

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
a=0
try:
    z=sorted([i for i, x in enumerate(S) if x == '#'],reverse=True)
    if len(z)>1:
        z=len(z)-1
    else:
        z=len(z)
    c=0
    tmp=""
    c=S.index("#")
    b=S.index(".")
    print(min(S[c:].count("."),z))
except:
    print(0)

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:
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

        if stone == "#":
            black_count += 1

    for stone in s[::-1]:
        if stone == "#":
            black_count -= 1

        else:
            break

    print(min(while_count, black_count))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

m1=0
m2=0

for i in range(n):
  if s[i] == '#':
    m1+=1
  if s[i] == '.':
    m2+=1

m3=0
a=0
for i in range(n):
  if n-i-1 == a:
    break
  if s[n-i-1] == '.':
    flag=0
    for j in range(a,n):
      if j == n-i-1:
        break
      if s[j] == '#':
        if n-j == m1:
          m3+=1
          flag=0
          break
        m3+=2
        a=j+1
        flag=1
        break
    if flag == 0:
      break

print(min(m1,m2,m3))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
if all(S)=="#" or all(S)==".":
    print(0)
    exit
else:
    pass
for i in reversed(range(N)):
    if S[i]==".":
        if i==0:
            break
        else:
            for j in range(1,i+1):
                if S[i-j]=="#":
                    count+=1
                else:
                    break
    else:
        pass

print(min(count,N-count))

Submission status: Wrong Answer

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

m1=0
m2=0

for i in range(n):
  if s[i] == '#':
    m1+=1
  if s[i] == '.':
    m2+=1

m3=0
a=0
for i in range(n):
  if n-i-1 == a:
    break
  if s[n-i-1] == '.':
    flag=0
    for j in range(a,n):
      if j == n-i-1:
        break
      if s[j] == '#':
        if n-j -2 == m1:
          m3+=1
          flag=0
          break
        m3+=2
        a=j+1
        flag=1
        break
    if flag == 0:
      break

print(min(m1,m2,m3))

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 = "...."


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

    return np.max(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)))

Submission status: Wrong Answer

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

def trim(s):
    i = 0
    while i < n and s[i] == '.':
        i += 1
    start = i

    i = n
    while i > 0 and s[i - 1] == '#':
        i -= 1
    end = i

    return s[start:end]


s = trim(s)
i = 0
bw = []

while i < len(s):
    bs = 0
    ws = 0
    while i < len(s):
        if s[i] == '#':
            bs += 1
            i += 1
        else:
            break
    while i < len(s):
        if s[i] == '.':
            ws += 1
            i += 1
        else:
            break

    bw.append(bs)
    bw.append(ws)


a = [0 for _ in range(len(bw) + 2)]

i = 2
while i < len(a):
    a[i] = a[i - 2] + bw[i - 2]
    a[i + 1] = a[i - 1] + bw[i - 1]
    i += 2

i = 2
can = len(s)

while i < len(a):
    head = min(a[i - 1], a[i - 2])
    tail = min(a[-1] - a[i - 2], a[-2] - a[i - 1])
    can = min(can, head + tail)
    i += 2

print(can)

Submission status: Wrong Answer

Solution code:
print(2)

Submission status: Wrong Answer

Solution code:
import sys
import numpy
from collections import Counter

def calc(N,S):
    if '#' not in S or '.' not in S:
        return 0        
    i =0
    for x in S:
        if x == '#':
            F = S[i:]
            return min(Counter(F).values())
        i+=1

if __name__ == '__main__':
    N = input()
    S = input()
    print(calc(N,S))

Submission status: Wrong Answer

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

m1=0
m2=0

for i in range(n):
  if s[i] == '#':
    m1+=1
  if s[i] == '.':
    m2+=1

m3=0
a=0
for i in range(n):
  if n-i-1 == a:
    break
  if s[n-i-1] == '.':
    flag=0
    for j in range(a,n):
      if j == n-i-1:
        break
      if s[j] == '#':
        if n-j -1 == m1:
          m3+=1
          flag=0
          break
        m3+=2
        a=j+1
        flag=1
        break
    if flag == 0:
      break

print(min(m1,m2,m3))

Submission status: Wrong Answer

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

length = []
cnt = 0
now = "#"
length_sum = []
length_num = 0
change = ""

ans = 0
for i in S:
  if now == i:
    cnt += 1
  else:
    if now == "#":
      now = "."
    else:
      now = "#"
    length.append(cnt)
    length_num += 1
    if length_num > 1 and length_num % 2 == 0:
        if length_num > 2:
            
            if change == "min":
                ans += min(length[length_num-2],length[-1])
            elif change == "#":
                ans += length[length_num-2]
            else:
                ans += length[-1]
                
        else:
            ans += min(length[length_num-2],length[-1])

            if length[length_num-2] == length[-1]:#==.
                change = "min"
            elif length[length_num-2] < length[-1]:#<.
                change = "#"
            else:#>.
                change = "."
            
    cnt = 1
else:
    length.append(cnt)
    length_num += 1
    if length_num > 1 and length_num % 2 == 0:
        if length_num > 2:
            
            if change == "min":
                ans += min(length[length_num-2],length[-1])
            elif change == "#":
                ans += length[length_num-2]
            else:
                ans += length[-1]
                
        else:
            ans += min(length[length_num-2],length[-1])

            if length[length_num-2] == length[-1]:#==.
                change = "min"
            elif length[length_num-2] < length[-1]:#<.
                change = "#"
            else:#>.
                change = "."

print(ans)

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 = []
    for n in range(N):
        if S[n] == "#":
            B_list.append(n)
        else:
            W_list.append(n)
    if len(B_list) ==0 or len(W_list)==0:
        print(0)
        sys.exit()
    cnt_b =0
    for i, b in enumerate(B_list):
        if i == 0:
            continue
        else:
            cnt_b += B_list[i]-B_list[i-1]-1
    if W_list[-1] >= B_list[-1]:
        cnt_b += W_list[-1] - B_list[-1]
    cnt_w = 0
    for i, w in enumerate(W_list):
        if i == 0:
            continue
        else:
            cnt_w += W_list[i]-W_list[i-1]-1
    if W_list[0] >= B_list[0]:
        cnt_w += W_list[0] - B_list[0]
    
    print(min(cnt_w, cnt_b))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

idxs = [i for i, x in enumerate(s)
       if x==1]

if len(idxs)==0 or len(idxs)==n:
  print(0)
  
else:  
  s = np.array(s)
  ans = [len(idxs)]
  prev_idx = -2

  for i, idx in enumerate(idxs):
    diff = idx - prev_idx
    prev_idx = idx
    if diff>1:    
      whites = np.sum(s[idx+1:]==0)
      ans.append(i + whites)
      print(i, idx)

      if whites==0:
        break
        
  print(np.min(ans))

Submission status: Wrong Answer

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

flag = False
k = 0
sb = 0
sa = 0 
for i in range(int(l)):
    if S[i] == "#":
        flag=True
        k += 1
    elif flag :
        sa += 1
    else:
        sb +=1


if sb == l:
    print(0)
elif sa == 0:
    print(min(sb, k))
else:
    print (min(sa,k))

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

        if stone == "#":
            black_count += 1

    print(min(while_count, black_count))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

acc = [0]
for i in range(N):
    s = S[i]
    if s == ".":
        acc.append(acc[-1] + 1)
    else:
        acc.append(acc[-1])
acc.pop(0)
ans = 0
T1 = S.copy()

while len(T1) != 0 and T1[-1] == "#":
    T1.pop()
N = len(T1)
now = 0
prev = ""
for i in range(N):
    s = T1[i]
    if s == ".":
        if prev == "#":
            ans += now
        now = 0
    else:
        now += 1
        if prev == "#":
            if acc[-1] - acc[i] < now:
                ans += acc[-1] - acc[i]
                break
        else:
            now = 0
            ans += 1
    prev = s
ans2 = 0
N = len(S)
for i in range(N):
    s = S[i]
    if s == ".":
        continue
    else:
        ans2 += 1

ans3 = 0

for i in range(N):
    s = S[i]
    if s == ".":
        ans3 += 1
    else:
        continue

print(min(ans2, ans, ans3))

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

        elif stone == "#":
            black_count += 1

        else:
            buff = stone

    print(min(while_count, black_count))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a=int(input())
b=list(input())
white_stone=b.count(".")
black_stone=b.count("#")
if "#" in b:
    #print(b)
    b.reverse()
    sep=b.index("#")+1
    #print(b)
    #print(sep)
    target_black=b[sep:]
    target_white=b[:sep]
    #print(target_black)
    #print(target_white)
    print(min([target_black.count("#"),b.count("#")]))
else:
    print(min(white_stone,black_stone))

Submission status: Wrong Answer

Solution code:
import sys
import numpy
from collections import Counter

def calc(N,S):
    if '#' not in S or '.' not in S:
        return 0        
    i =0
    for x in S:
        if x == '#':
            F = S[i:]
        i+=1
    return min(Counter(F).values())

if __name__ == '__main__':
    N = input()
    S = input()
    print(calc(N,S))

Submission status: Wrong Answer

Solution code:
print(10)

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)

cnt = 0
if len(ar) > 0 and ar[-1].count('#') > 0:
    ar.pop(-1)
if len(ar) > 0 and ar[0].count('.') > 0:
    ar.pop(0)
while True:
    if len(ar) < 2:
        break
    last = ar[-1]
    last2 = ar[-2]
    if len(last2) >= len(last):
        cnt += len(last)
        ar.pop(-1)
        ar.pop(-1)
    else:
        break

new_s = ''.join(ar)

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

cnt += min(a,b)
print cnt

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

        elif 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:
print()

Submission status: Wrong Answer

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

length = []
cnt = 0
now = "#"
length_sum = []
length_num = 0
change = ""

ans = 0
for i in S:
  if now == i:
    cnt += 1
  else:
    if now == "#":
      now = "."
    else:
      now = "#"
    length.append(cnt)
    length_num += 1
    if length_num > 1 and length_num % 2 == 0:
        if length_num > 2:
            
            if change == "min":
                ans += min(length[length_num-2],length[-1])
            elif change == "#":
                ans += length[length_num-2]
            else:
                ans += length[-1]
                
        else:
            ans += min(length[length_num-2],length[-1])

            if length[length_num-2] == length[-1]:#==.
                change == "min"
            elif length[length_num-2] < length[-1]:#<.
                change == "#"
            else:#>.
                change == "."
            
    cnt = 1
else:
    length.append(cnt)
    length_num += 1
    if length_num > 1 and length_num % 2 == 0:
        if length_num > 2:
            
            if change == "min":
                ans += min(length[length_num-2],length[-1])
            elif change == "#":
                ans += length[length_num-2]
            else:
                ans += length[-1]
                
        else:
            ans += min(length[length_num-2],length[-1])

            if length[length_num-2] == length[-1]:#==.
                change == "min"
            elif length[length_num-2] < length[-1]:#<.
                change == "#"
            else:#>.
                change == "."

print(ans)

Submission status: Wrong Answer

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

m1=0
m2=0

for i in range(n):
  if s[i] == '#':
    m1+=1
  if s[i] == '.':
    m2+=1

m3=0
a=0
for i in range(n):
  if n-i-1 == a:
    break
  if s[n-i-1] == '.':
    flag=0
    for j in range(a,n):
      if j == n-i-1:
        break
      if s[j] == '#':
        m3+=2
        a=j+1
        flag=1
        break
    if flag == 0:
      break

print(min(m1,m2,m3))

Submission status: Wrong Answer

Solution code:
n = int(input())
ss = input()
flag = True
ans =  0
black = ss.count('#')
for s in ss:
    if black >= n - black:
        if flag:
            if s == '#':
                flag = False
        else:
            if s == '.':
                ans += 1
    else:
        if s == '#':
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy
from collections import Counter

def calc(N,S):
    if '#' not in S or '.' not in S:
        return 0        
    i =0
    for x in S:
        if x == '#':
            F = S[i:]
        i+=0
    return min(Counter(F).values())

if __name__ == '__main__':
    N = input()
    S = input()
    print(calc(N,S))

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 = "...."


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

    return np.max(left_black_stones - right_white_stones)


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

Submission status: Wrong Answer

Solution code:
import sys
import numpy
from collections import Counter

def calc(N,S):
    if '#' not in S:
        return 0
    i =0
    for x in S:
        if x == '#':
            F = S[i:]
        i+=0
    return min(Counter(F).values())

if __name__ == '__main__':
    N = input()
    S = input()
    print(calc(N,S))

Submission status: Wrong Answer

Solution code:
print(1)