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:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    S = list(_ for _ in input())
    ans = 0
    for i in range(N-1):
        if(S[i]=='#' and S[i+1]=='.'):
            ans +=1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


S2 = S.split("#")[1:]
if S2 == S:
        print("0")
else:
    sn = S2.count(".")
    print(sn)

Submission status: Wrong Answer

Solution code:
n,s=int(input()),input()
w,b=s[0],s[-1]
wc,bc=0,0
for i in range(n-1):
  if b[0]=="."and"#"==s[n-2-i]:b="."+b;bc+=1
  else:b=s[n-2-i]+b
  if w[-1]=="#"and"."==s[i+1]:w+="#";wc+=1
  else:w+=s[i+1]
print(min(bc,wc))

Submission status: Wrong Answer

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

ans1 = 0
flag = 0
for i in range(1,N+1):
    if S[-i] == '.':
        flag = 1
    else:
        if flag == 1:
            ans1 += 1

flag = 0
ans2 = 0
for j in range(N):
    if S[j] == '#':
        flag = 1
    else:
        if flag == 1:
            ans2 += 1

print(min(ans1,ans2))

Submission status: Wrong Answer

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

w = S.count(".")
b = S.count("#")

print(min(w,b))

Submission status: Wrong Answer

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

white = S.count(".")
ans = min(white, N - white)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s1 = '.' + (n - 1) * '#'
s2 = (n - 1) * '.' + '"'
s3 = n * '.'
s4 = n * '#'
p = [0, 0, 0, 0]
for i in range(n):
    if s[i] != s1[i]:
        p[0] += 1
    if s[i] != s2[i]:
        p[1] += 1
    if s[i] != s3[i]:
        p[2] += 1
    if s[i] != s4[i]:
        p[3] += 1
print(min(p))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = input()
pt = S.find("#")
ct = 0
if pt == -1:
    print(0)
else:
    for i in range(pt, N):
        if S[i] == ".":
            ct += 1
    print(ct)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
prev = S[0]
for i in range(1, len(S)):
    if prev == '#' and S[i] == '.':
        S[i] == '#'
        cnt += 1
    prev = S[i]
    
print(cnt)

Submission status: Wrong Answer

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

kurodeta = False
cnt = 0
for stone in S:
    if not kurodeta and stone == ".":
        continue

    if stone == "#":
        kurodeta = True

    if stone == ".":
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

# 四方向
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]
INF = float("inf")

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))

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:
N = int(input())
S = input()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
idx = []
for i in range(n-1):
  if s[i] == '#' and s[i+1] == '.':
    idx.append(i+1)

print(len(idx))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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



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

print(score)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
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
print(c)

Submission status: Wrong Answer

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

cnt = 0
for s in S:
    if s == ".":
        cnt += 1
    else:
        break
S = S[cnt:]
print(S.count("."))

Submission status: Wrong Answer

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

white = 0
black = 0
for c in S:
    if c == ".":
        white += 1
    else:
        black += 1
print(min(white, black))

Submission status: Wrong Answer

Solution code:
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break

print(min(S.count('#'), S[left:].count('.')))

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  s = input()
  ans = 0
  a = s.count(".")
  b = s.count("#")
  count = 0
  if a == n:
    print("0")
  else:
    for i in range(n):
      if s[i] =="#":
        print(a-count)
        exit()
      else:
        count += 1
        
solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
arg=0
if "#" not in s:
    print(0)
    exit()
for i in range(n):
    if s[i]=="#":
        arg=i
        break

print(s[arg:].count("."))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
cou = 0
for i,s in enumerate(S):
    if s=='#':
        for j in range(N-1,i,-1):
            if S[j]=='.':
                cou+=1
        break
print(cou)

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnta = s.count("#")
cntb = s.count(".")
ans = min(cnta,cntb)
for i in range(N):
	if s[i] == "#":
		tmp = i
		ans = min(ans,N-i+1)
		break

print(ans)

Submission status: Wrong Answer

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

flag = False
cnt = 0

for s in S:
    if s == "#":
        flag = True
    if flag:
        if s == ".":
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = input()

state = None
count = 0
for i in range(len(S)):
	if state == "#" and S[i] == ".":
		count += 1
	state = S[i]
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input().rstrip()
    i = 0
    b_count = 0
    w_count = 0
    while i < len(s):
        if s[i] == '.':
            i += 1
        else:
            break
    while i < len(s):
        if s[i] == '.':
            i += 1
            w_count += 1
        else:
            i += 1
            b_count += 1

    print(min(w_count, b_count))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


# 最初の黒以降の白全部置き換える
ans = 0
found = False
for c in S:
    if c == '.' and found:
        ans += 1
    if c == '#':
        found = True
print(ans)

Submission status: Wrong Answer

Solution code:

def kari():
    N = list(map(int, input().split()))
    A, B = map(int, input().split())

def main():
    N = int(input())
    S = list(input())

    flg = 0
    ans = 0
    for i in range(N):
        if S[i] == '#':
            flg = 1
        if flg and S[i] == '.':
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
t=s.find("#")
if t==-1:
    print(0)
else:
    print(s[t:].count("."))

Submission status: Wrong Answer

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


for i in range(len(stone) - 1):
  if stone[i] == '#' and stone[i+1] == '.':
    cnt = 0
    for s in stone[i+1:]:
      if s == '.':
        cnt += 1
        
    print(cnt)
    exit()

print('0')

Submission status: Wrong Answer

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

print(S[S.find("#"):].count(".") if S.find("#") != -1 else 0)

Submission status: Wrong Answer

Solution code:
import re
import sys
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    S = ii(str)
    s = re.findall("#[.]+", S)
    return len(s)


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())  # 数値入力
str = list(input())  # 一文字ずつ格納
print(min(str.count("."), str.count("#")))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
arg=0
for i in range(n):
    if s[i]=="#":
        arg=i
        break
print(s[arg:].count("."))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=0
now="."
for i in s:
  if now=="#" and i==".":
    ans+=1
  else:
    now=i
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = s.find("#")
if a == -1:
    print(0)
else:
    print(s[a:].count("."))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
if "#" not in S:
	print(0)
else:
	i=S.index("#")
	print(min(S[i:].count("#"), S[i:].count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
listS=list(input())
count=0
index=0
bef=0
while index < len(listS):
    if index == 0:
        bef = listS[index]
    else:
        if bef == "#":
            if listS[index] == ".":
                count+=1
        bef = listS[index]
    index+=1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
flag = False
for char in S:
    if flag:
        if char == ".":
            ans += 1
            continue
        continue
    if char == "#":
        flag = True
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
for x in S:
    if x == '.':
        ans += 1
num = 0
for x in S:
    if x == '#':
        break
    elif x == '.':
        num += 1
print(ans-num)

Submission status: Wrong Answer

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
n = ip()                                     #入力整数1つ
#a,b,c= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(3)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
x,y = 0,0
for i in range(n):
    if a[i] == '#':x+=1
    else: y+=1
print(min(x,y))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder C
"""

def main():
    N=input()
    S=list(map(str,input().split()))[0]
    tmp=False
    num=0
    for s in S:
        # print(s,tmp)
        if s=="#":
            tmp=True
        elif s=="." and tmp:
            num+=1
    print(num)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

N=input()
S=input()
Slist =list(N)
Sg=Slist[0::2]
Sk=Slist[1::2]
SG = ''.join(Sg)
SK = ''.join(Sk)
a=SG.count(".")
b=SG.count("#")
x=SK.count(".")
y=SK.count("#")
	
print(min(a+y,b+x))

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

ans = 0

for i in range(1,N):
    if S[i] == '.':
        if S[i-1] == '#':
            ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

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

ans = float('inf')

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
print(min(s[:i].count('#')+s[i:].count('.') for i in range(n+1)))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = input()
    ans = 10**10
    for i in range(n):
        lc = s[:i+1].count(".")
        rc = s[i:].count("#")
        tmp = n - lc - rc
        if tmp < ans:
            ans = tmp
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


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


# In[8]:


ans = N
for i in range(N+1):
    left = S[:i].count("#")
    right = S[i:].count(".")
    ans = min(ans, left+right)
print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

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

w = S.count('.')
b = S.count('#')
cnt = N+1
for i in range(1, N+1):
  tmp = S[:i].count('#') + S[i:].count('.')
  cnt = min(cnt, tmp)
    
ans = min(w, b, cnt)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
while True:
    T = S.replace('#.','')
    if T == S:
        break
    else:
        S = T
print((N-len(S))//2)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = list(input())
ans = 10 ** 9
for i in range(N + 1):
  ans = min(ans,Counter(S[:i])["#"] + Counter(S[i:])["."])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = 10 ** 9
for i in range(N + 1):
  ans = min(ans,S[:i].count("#") + S[i:].count("."))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
a=[0]
for i in s:
    if i==".":a+=[a[-1]+1]
    else:a+=[a[-1]]
print(min(i-a[i]*2+s.count(".") for i in range(n+1)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
from itertools import groupby
from collections import deque
s=list(input())
gr=groupby(s)
#flg=0:白の状態
flg=0
black=[]
white=[]
for k,v in gr:
    if flg==0 and k=='#':
        flg=1
        black.append(len(list(v)))
    elif flg==1:
        if k=='#':
            black.append(len(list(v)))
        else:
            white.append(len(list(v)))
if len(black)==0 or len(white)==0:
    print(0)
    exit(0)


cnt=sum(white)
white=deque(white)
black=deque(black)
for _ in range(len(white)):
    white.popleft()
    white.append(black.popleft())
    cnt=min(cnt,sum(white))

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
from itertools import groupby
from collections import deque
s=list(input())
gr=groupby(s)
#flg=0:白の状態
flg=0
black=[]
white=[]
for k,v in gr:
    if flg==0 and k=='#':
        flg=1
        black.append(len(list(v)))
    elif flg==1:
        if k=='#':
            black.append(len(list(v)))
        else:
            white.append(len(list(v)))
if len(black)==0 or len(white)==0:
    print(0)
    exit(0)

ans=white.copy()
cnt=sum(ans)

white=deque(white)
black=deque(black)
ans=deque(ans)

while white:
    ans.popleft()
    white.popleft()
    ans.append(black.popleft())
    cnt=min(cnt,sum(ans))

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
ans = s.count('#')
for i in range(n):
    w = s[:i].count('#')
    b = s[i:].count('.')
    ans = min(ans, w + b)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
S = input()
min_stone = Counter(S).most_common()[-1][1]
if min_stone == N:
    min_stone = 0

for i in range(1,N):
    A, B = Counter(S[:i])['#'], Counter(S[i:])['.']
    if min_stone > A+B:
        min_stone = A+B
print(min_stone)

Submission status: Time Limit Exceeded

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

# from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
from collections import Counter, deque, defaultdict

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

mi = 10000000

c = Counter(S)
A = N - c["#"]
B = N - c["."]

for i in range(1, N):
    l = S[:i]
    r = S[i:]
    a = l.count("#") + r.count(".")
    if mi > a:
        mi = a

print(min(mi, A, B))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = str(input())
S = list(s[i] for i in range(N))

test = S
countf = 0

if S == list(sorted(S)[::-1]):
    print(0)

else:
    while test != list(sorted(test)[::-1]):
        a = test.index("#")
        test[a] = "."
        countf += 1
        del test[0:a+1]
        if test == list(sorted(test)[::-1]):
            break
        test.reverse()
        b = test.index(".")
        test[b] = "#"
        countf += 1
        del test[0:b+1]
        test.reverse()

    print(countf)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = str(input())
S = list(s[i] for i in range(N))

test = S
countf = 0

if S == list(sorted(S)[::-1]):
    print(0)

else:
    while test != list(sorted(test)[::-1]):
        test[test.index("#")] = "."
        countf += 1
        if test == list(sorted(test)[::-1]):
            break
        test[s.rfind(".")] = "#"
        countf += 1

    print(countf)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = str(input())
S = list(s[i] for i in range(N))

test = S
#testb = S

countf = 0
countb = 0
#print(test)
#print(s)

if S == list(sorted(S)[::-1]):
    print(0)

else:
    while test != list(sorted(test)[::-1]):
        del test[test.index("#")]
        test.insert(0, ".")
        countf += 1
        #print(test)
        if test == list(sorted(test)[::-1]):
            break
        del test[s.rfind(".")]
        test.append("#")
        countf += 1
        #print(test)


#    while testb != list(sorted(testb)[::-1]):
#        del testb[testb.rindex(".")]
#        testb.append("#")
#        countb += 1
#        print(testb)
#        if testb == list(sorted(testb)[::-1]):
#            break
#        del testb[testb.index("#")]
#        testb.insert(0, ".")
#        countb += 1
#        print(testb)

#if countf<countb:
    print(countf)
#else:
#    print(countb)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=[0 if i=='.' else 1 for i in input()]
if sum(S)==0 or sum(S)==n:
    print(0)
    exit()
allblack=n-sum(S)
allwhite=sum(S)
bw=10**6
from itertools import accumulate
accS=list(accumulate(S))
for i in range(n):
    bw=min(bw,accS[i]+(n-(i+1))-(sum(S)-accS[i]))
print(min(bw,allblack,allwhite))

Submission status: Time Limit Exceeded

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


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

for i in range(1,N):
    t = 0
    t += S[:i].count("#")
    t += S[i:].count(".")
    t_min = min(t_min, t)
print(t_min)

Submission status: Time Limit Exceeded

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

ans=float("inf")
for i in range(n+1):
    left=s[0:i]
    right=s[i:n]
    tmp=(left.count("#")+right.count("."))
    # print(left,right,tmp)
    ans=min(ans,tmp)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
S = list(str(input()))

C = ["#" for _ in range(N)]

minN = sys.maxsize
for i in range(N+1) :
  cnt = 0
  for j in range(N) :
    if S[j] != C[j] :
      cnt += 1
  minN = min(minN, cnt)
  if i < N :
    C[i] = "."

print (minN)

Submission status: Time Limit Exceeded

Solution code:
n =int(input())
s = input()
res = 10**6
for i in range(0,n+1):
    tres = s[:i].count("#") + s[i:].count(".")
    res = min(res,tres)

print(res)

Submission status: Time Limit Exceeded

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

l=[]
i=n
aa=s.rfind('.')
bb=s.find('.')
ans=min(s[:aa+1].count('.'),s[:aa+1].count('#'))
while i>=0:
    a=s[:i].rfind('.')
    ans=min(ans,(1+min(s[:a+1].count('.'),s[:a+1].count('#'))))
    #print(ans,a)
    i=a
    if a==bb:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n = int(input())
    s = input()
    if len(set(s)) == 1:
        print(0)
    else:
        ans = min(s.count("."), s.count("#"))
        for i in range(n):
            if s[i:i + 2] == ".#":
                t = s[:i + 1].count("#") + s[i + 1:].count(".")
                if t < ans:
                    ans = t
        print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(input())
count = 0
for i in range(N):
    try:

        if S.count('.') <= S.count('#'):
            
            if S[i] =='#':

                if S[i+1] == '.':

                    S[i+1] = '#'

                    count += 1
                
        elif S.count('.') > S.count('#'):

            if S[i] == '.':

                if S[i+1]=='#':

                    S[i+1] = '.'

                    count +=1

    except IndexError:

        break

print(count)

Submission status: Time Limit Exceeded

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

ans=1145141919
for i in range(n+1):
    ans = min(ans, (s[:i].count("#")+s[i:].count(".")))
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
a=[S[:i].count("#")+S[i+1:].count(".") for i in range(N)]
print(min(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
s=input()
l=np.array([0])
r=np.array([0])
for i in range(n):
    if s[i]=="#":
        l=np.append(l,l[i]+1)
    else:
        l=np.append(l,l[i])
    if s[n-i-1]==".":
        r=np.append(r,r[i]+1)
    else:
        r=np.append(r,r[i])
r=r[::-1]
print(min(l+r))

Submission status: Time Limit Exceeded

Solution code:
import re

pattern_black = re.compile('#')
pattern_white = re.compile(r'\.')
n = int(input()) 
stones = input()
count = 0


for i in range(1, len(stones)):
  if pattern_black.match(stones[i-1]) and pattern_white.match(stones[i]):
    stones = stones[:i] + '#' + stones[i+1:]
    count += 1
    
print(count)

Submission status: Time Limit Exceeded

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

for i in range(1, len(stones)):
  if stones[i-1] is '#' and stones[i] is '.':
    stones = stones[:i] + '#' + stones[i+1:]
    count += 1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = n
for m in range(n+1) :
    r = s[:m].count("#")
    t = s[m:].count(".")
    ans = min(ans, r+t)
print(ans)

Submission status: Time Limit Exceeded

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

answer = n

for i in range(n + 1):
    answer = min(answer, s[:i].count("#") + s[i:].count("."))

print(answer)

Submission status: Time Limit Exceeded

Solution code:
# TPBC201C - Stones
n = int(input())
s = input()
if len(set(s)) == 1:
    print(0)
else:
    ans = n
    for i in range(len(s)):
        ans = min(ans, s[:i].count("#") + s[i:].count("."))
    print(ans)

Submission status: Time Limit Exceeded

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


min_count = n

for border in range(n + 1):
	count = 0
	for i, bw in enumerate(s):
		if i < border and bw == '#':
			count += 1
		elif i >= border and bw == '.':
			count += 1

		if count >= min_count:
			break

	if min_count > count:
		min_count = count

print(min_count)

Submission status: Time Limit Exceeded

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

def countHand(st, pos):
  left_b = st[:pos].count('#')
  right_w = st[pos:].count('.')
  count = left_b + right_w
  return count
  
minHand = 2 * 10 **5
for i in range(len(S)+1):
  ret = countHand(S, i) 
  if ret <= minHand:
    minHand = ret

ans = minHand
print("{}".format(ans))

Submission status: Time Limit Exceeded

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

W = S.count('.') #全部の白の数
B = N - W #全部の黒の数

count = N

for i in range(0,N+1):
    a = S[0:i]
#    print (a)
    w = a.count('.') #前半の白の数
    b = i - w #前半の黒の数
    count = min(count, b+(W-w)) #反転すべき数 = 前半の黒の数＋後半の白の数
print (count)

Submission status: Time Limit Exceeded

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

kouho = []
kouho.append(['.' for i in range(N)])
for i in range(1, N+1):
    a = kouho[-1][:]
    a[-i] = '#'
    kouho.append(a)

counts = []
for k in kouho:
    count = 0
    for i in range(N):
        if k[i] != S[i]:
            count += 1
    counts.append(count)

print(min(counts))

Submission status: Time Limit Exceeded

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

count=[0]*(len(S)+1)
for i in range(len(S)+1):
    count[i]=(S[:i].count('#')+S[i:].count('.'))

print(min(count))

Submission status: Time Limit Exceeded

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

count=[]
for i in range(len(S)+1):
    left = S[:i]
    right = S[i:]
    count.append(left.count('#')+right.count('.'))

print(min(count))

Submission status: Time Limit Exceeded

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

count=[]
for i in range(len(S)+1):
    count_temp=0
    left = S[:i]
    right = S[i:]
    for _ in left:
        count_temp += 1 if _!='.' else 0
    for _ in right:
        count_temp += 1 if _!='#' else 0
        
    count.append(count_temp)

print(min(count))

Submission status: Time Limit Exceeded

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


num=S.count("#")
if num>S.count("."):#全部黒にする
  num=S.count(".")
  
for i in range(0,N): #i番目まで白
  n=S.count("#",0,i)+S.count(".",i+1,N)

  if n<num:
    num=n
 
print(num)