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: 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=0
  for j in range(0,i):
    if S[j]=="#":
      n=n+1
      if n>=num: break
  for k in range(i,N):
    if S[k]==".":
      n=n+1    
      if n>=num: break
  if n<num:
    num=n
 
print(num)

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=0
  for j in range(0,i):
    if S[j]=="#":
      n=n+1
  for k in range(i,N):
    if S[k]==".":
      n=n+1    
  if n<num:
    num=n
 
print(num)

Submission status: Time Limit Exceeded

Solution code:

# -*- coding: utf-8 -*-

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

# 0 0 1 1 全部黒
# 0 1 2 2
# 0 1 1 1
# 0 1 1 2 全部白
#  # . #

sum = [0]*(n+1)
ans = n

for i in range(n+1):
    for j in range(0,i):
        # print('i = {}, j = {}'.format(i,j))
        if s[j] == '#':
            sum[j+1] = sum[j] + 1
        else:
            sum[j+1] = sum[j]
        if sum[j+1]>ans:
            break

    for k in range(i, n):
        # print('i = {}, k = {}'.format(i,k))
        if s[k] == '.':
            sum[k+1] = sum[k] + 1
        else:
            sum[k+1] = sum[k]
        if sum[k+1]>ans:
            break
    ans = min(ans, sum[n])
print(ans)

Submission status: Time Limit Exceeded

Solution code:

# -*- coding: utf-8 -*-

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

# 0 0 1 1 全部黒
# 0 1 2 2
# 0 1 1 1
# 0 1 1 2 全部白
#  # . #


ans = n

for i in range(n+1):
    sum = [0]*(n+1)
    for j in range(0,i):
        # print('i = {}, j = {}'.format(i,j))
        if s[j] == '#':
            sum[j+1] = sum[j] + 1
        else:
            sum[j+1] = sum[j]
        if sum[j+1]>n:
            break

    for k in range(i, n):
        # print('i = {}, k = {}'.format(i,k))
        if s[k] == '.':
            sum[k+1] = sum[k] + 1
        else:
            sum[k+1] = sum[k]
        if sum[k+1]>n:
            break
    ans = min(ans, sum[n])
print(ans)

Submission status: Time Limit Exceeded

Solution code:

# -*- coding: utf-8 -*-

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

# 0 0 1 1 全部黒
# 0 1 2 2
# 0 1 1 1
# 0 1 1 2 全部白
#  # . #

sum = [0]*(n+1)
ans = n

for i in range(n+1):
    for j in range(0,i):
        # print('i = {}, j = {}'.format(i,j))
        if s[j] == '#':
            sum[j+1] = sum[j] + 1
        else:
            sum[j+1] = sum[j]

    for k in range(i, n):
        # print('i = {}, k = {}'.format(i,k))
        if s[k] == '.':
            sum[k+1] = sum[k] + 1
        else:
            sum[k+1] = sum[k]
    ans = min(ans, sum[n])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
S = input()
"""
黒い石のすぐ右に白い石がない
すなわち
    左から白がいくつか連続で並び残りが黒
    全て黒石
    全て白石
のいずれかを満たせば良い
それぞれの状態にするために変更する必要のある石の数をN_1, N_2, N_3とする
......#########
#.
"""

N_1 = 10^6
N_2 = S.count(".")
N_3 = S.count("#")

for i in range(N):
    if S[i] == "#":
        ret = S[0:i].count("#") + S[i:N].count(".")
        if ret < N_1:
            N_1 = ret

print(min(N_1, N_2, N_3))

Submission status: Time Limit Exceeded

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

WtoBcounter = 0
for i in range(N):
    if S[i] == "#":
        for j in range(i+1, N):
            if S[j] == ".":
                WtoBcounter += 1
        break

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

output = 0
if WtoBcounter < BtoWcounter:
    output = WtoBcounter
else:
    output = BtoWcounter

print(output)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
lst = []
count = N
for n in range(N+1):
    c = S[:n].count("#") + S[n:].count(".")
    count = min(c, count)
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
min = N
i = 0
for i in range(N + 1):
    b = S[:i]
    f = S[i:]
    T = b.count('#') + f.count('.')
    if T < min:
        min = T

print(min)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
lst = []
for n in range(N+1):
    lst.append(S[:n].count("#") + S[n:].count("."))
print(min(lst))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
black_appered = False
ans = 10**9
count =0
# [BBB...WWW...]の組を抽出する
for i in range(n+1):
    left = s[:i]
    right = s[i:]
    count = left.count('#') + right.count('.')
    ans = min(ans,count)
    # print(left," | ", right," | ", count, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
input()
src = list(map(lambda x: 1 if x=="#" else 0, input()))
s = sum(src)
l = len(src)
ans = s
for i in range(len(src)):
  ans = min(ans, 2*sum(src[:i]) + l - i - s)
  if ans==0:
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
input()
src = list(map(lambda x: 1 if x=="#" else 0, input()))
ans = sum(src)
for i in range(len(src)):
  ans = min(ans, sum(src[:i]) + len(src[i:]) - sum(src[i:]))
  if ans==0:
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
input()
src = list(map(lambda x: 1 if x=="#" else 0, input()))
costs = [sum(src[:i]) + len(src[i:]) - sum(src[i:]) for i in range(len(src))]
costs.append(sum(src))
print(min(costs))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
input()
src = input()
costs = [reduce(lambda x,y: x+(1 if y=="#" else 0), src[:i], 0) + reduce(lambda x,y: x+(1 if y=="." else 0), src[i:], 0) for i in range(len(src))]
costs.append(reduce(lambda x,y: x+(1 if y=="#" else 0), src, 0))
print(min(costs))

Submission status: Time Limit Exceeded

Solution code:
def checkLeft(left):
    count = left.count('#')
    left = left.replace('#','.')

    return count

def checkRight(right):
    count = right.count('.')
    right = right.replace('.','#')

    if count == len(right):
        count = 0

    return count

#改行入力
N = int(input())
S = input()

count = 0

min = len(S)+1

for i in range(len(S)):
    # print(S[i])

    left = S[:i]
    right = S[i:]

    left_count = checkLeft(left)
    right_count = checkRight(right)

    result = left_count + right_count

    if result < min:
        min = result



print(min)

Submission status: Time Limit Exceeded

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


l_sum = []
r_sum = []
sum_list = []

l_c = 0
r_c = 0

for i in range(1,N):
	if S[i-1] == '#':
		l_c = l_c + 1
	l_sum.extend([l_c])
	if S[N-i] == '.':
		r_c = r_c + 1
	r_sum.insert(0,r_c)

l_sum.insert(0,0)
r_sum.extend([0])

sum_list = [x + y for (x,y) in zip(l_sum,r_sum)]
print(min(sum_list))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    S = input()
    nums = []
    for b in range(N+1):
        nums.append(num_change(S, b, N))
    print(min(nums))


def num_change(S, border, N):
    count = 0
    for i in range(N):
        if i < border:
            if S[i] == '#':
                count += 1
        else:
            if S[i] == '.':
                count += 1
    return count


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

minimum=N
for i in range (N+1):
  white=S[:i].count("#")
  black=S[i:].count(".")
  minimum=min(minimum, white+black)
print(minimum)

Submission status: Time Limit Exceeded

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

s1=[]
s2=[]

a_min=float('inf')
a=0

if S.count('#')==N or S.count('.')==N:
    print(0)
else:
    for i in range(N+1):
        s1=S[:i]
        s2=S[i:]
        a=min(s1.count('.'),s1.count('#'))+s2.count('.')
        if a<a_min:
            a_min=a
            
    print(a_min)

Submission status: Time Limit Exceeded

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

s1=[]
s2=[]
a_min=float('inf')
a=0

for i in range(N+1):
    s1=S[:i]
    s2=S[i:]
    a=min(s1.count('.'),s1.count('#'))+s2.count('.')
    if a<a_min:
        a_min=a
        
print(a_min)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
S = S + ['#']
l_sum = []

for i in range(len(S)):
    l_sum.extend([S[0:i].count('#')+S[i:len(S)].count('.')])

print(min(l_sum))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
 
ans = float("inf")
for i in range(len(S)+1):
  left = S[:i].count("#")
  right = S[i:].count(".")
  ans = min(ans, left + right)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
count = S.count("#.")
ans = 0

while count != 0:

    for i in range(count):
        bwindex = S.index("#.")
        S = list(S)
        S[bwindex+1] = "#"
        S = "".join(S)
        ans += 1

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

Submission status: Time Limit Exceeded

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

if '#' not in S or '.' not in S:
    ans = 0
else:
    ans = 2*10**5
    for i in range(N):
        ans = min(S[:i].count('#') + S[i:].count('.'), ans)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())  # 数値入�?
str = list(input())  # 一�?字ずつ格�?
ans = float("Inf")

for i in range(0, n+1):
    tmp = str[:i].count("#") + str[i:].count(".")

    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=float('inf')
wnum=0
bnum=0
for i in range(n+1):
  s1=s[:i]
  s2=s[i:]
#  print(s1,s2)
  wnum=s1.count('#')
  bnum=s2.count('.')
  cnt=min(cnt,wnum+bnum)

if s.count('#')==n or s.count('.')==n:
  cnt=0
  
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=float('inf')
wnum=0
bnum=0
for i in range(n+1):
  s1=s[:i]
  s2=s[i:]
#  print(s1,s2)
  wnum=s1.count('#')
  bnum=s2.count('.')
  cnt=min(cnt,wnum+bnum)

if s.count('#')==n or s.count('.')==n:
  cnt=0
  
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(input())
result = N
count = 0
white = [1 if n == '.' else 0 for n in a]
for i in range(N+1):
	count = i-sum(white[0:i])+sum(white[i:N])
	if result > count:
		result = count
print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
black = 0
white = 0
black2 = 0
white2 = 0
k = 0
ans = 0
for i in range(N - 1):
    if S[i] == "#" and S[i + 1] == ".":
        if k == 0:
            black = S[:i + 1].count("#")
            white = S[i + 1:].count(".")
            ans += min(black, white)
            k = 1
        elif k == 1:
            black2 = S[:i + 1].count("#")
            white2 = S[i + 1:].count(".")
            ans += min(black2 - black, white - white2)
            black = black2
            white = white2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
_,s=open(0);a=s.count('.'),
for i in s:a+=a[-1]+(i<'.'or-1),
print(min(a))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
sint = [0]
prev = S[0]
DEBUG = False
def dbg(*something):
    if DEBUG:
        print(*something)

for s in S:
    if prev == s:
        sint[-1] = sint[-1] + 1
    else:
        prev = s
        sint.append(1)
if len(sint) % 2 == 1:
    if S[0] == '#':
        sint = [0] + sint
    else:
        sint.append(0)
elif S[0] == '#':
    sint = [0] + sint + [0]
dbg(sint)

def count2(numSB,numSW):
    dbg('len:',len(sint))
    if len(sint) < 2:
        return 0
    sint.pop(0)
    sint.pop()
    
    if len(sint) < 2:
        return 0
    b = sint.pop(0)
    w = sint.pop()
    
    numSR =  b + w + count2(numSB-b,numSW-w)
    dbg(numSB,numSW,numSR)
    # if numSB <= numSW and numSB <= numSR:
    #     return numSB
    # elif numSW <= numSB and numSW <= numSR:
    #     return numSW
    # else:
    #     return numSR
    return numSR

def count3(numSB,numSW):
    dbg('len:',len(sint))
    numSR = 0
    while len(sint) >= 4:
    # if len(sint) < 2:
    #     return 0
        sint.pop(0)
        sint.pop()
    
    # if len(sint) < 2:
    #     return 0
        b = sint.pop(0)
        w = sint.pop()
    
        numSR =  b + w + numSR

    # if numSB <= numSW and numSB <= numSR:
    #     return numSB
    # elif numSW <= numSB and numSW <= numSR:
    #     return numSW
    # else:
    #     return numSR
    return numSR

def hoge(numSW):
    fuga = [1 for i in range(N)]
    numc = numSW
    numcmin = numc
    for s in S:
        if s == '#':
            #b2w
            numc = numc + 1
        else:
            numc = numc -1
            if numc < numcmin:
                numcmin = numc
    return numcmin


numSB = 0
numSW = 0
for i,v in enumerate(sint):
    if i % 2 == 1:
        numSB = numSB + v
    else:
        numSW = numSW + v

numSR = count3(numSB,numSW)
dbg('numSW:',numSW)
dbg('numSB',numSB)
dbg('numSR',numSR)
print(hoge(numSW))
'''
22
#####.....####..###...####....#.#.#
...################################
'''

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

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

black = [0] * (n+1)
white = [0] * (n+1)
ans = [0] * (n+1)
for i in range(n+1):
  black[i] = s[:i].count("#")
  white[i] = s[i:].count(".")
  ans[i] = black[i] + white[i]
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
b = N
for i in range(0, N):
    c = S[0: i].count("#")
    d = S[i+1: N].count(".")
    if c + d < b:
        b = c + d
print(b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
count = 0
list_count =[]
for i in range(N+1):
    count = 0
    for j,s in enumerate(S):
        if(( i > j ) and (s != ".")):
            count+=1
        elif((i <= j) and (s != "#")):
            count+=1
        else:
            pass
    list_count.append(count)
print(min(list_count))

Submission status: Time Limit Exceeded

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

def next(s):
  if s == '':  # empty
    return 0, 0, None
  if len(s) == s.count('#') or len(s) == s.count('.'):  # . or # only
    return s.count('#'), s.count('.'), None

  l = s.index('#')
  try:
    c = s.index('#.')+1
    try:
      r = s.index('.#')+1
    except:
      r = len(s)-1
  except:
    c,r = len(s)-1
  b = c - l
  w = r - c
  return b, w, s[r:]

black, white = 0, 0
if n == s.count('#') or n == s.count('.'):  # . or # only
  black += s.count('#')
  white += s.count('.')
  s = None
else:
  if s[0] == '.':
    s = s[s.index('.#')+1:]
while(s != None):
  b, w, s = next(s)
  black += b
  white += w
print(min(black, white))

Submission status: Time Limit Exceeded

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

ans = N
for i in range(N + 1):
    left_num = S[:i].count('#')
    right_num = S[i:].count('.')

    if right_num == N - i:
        right_num = 0
    ans = min(ans, (left_num + right_num))
    if right_num in [0, N - i] or left_num > right_num:
        break
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
stone=int(input())
color=input()
result=100000
counter=0
left=''
right=''
if color.count('#') == 0 or color.count('.') == 0:
	result=0
else:
	for i in range(stone):
		left=color[:i]
		right=color[i:]
		w=left.count('#')
		b=right.count('.')
		if result > w+b:
			result=w+b
print(result)

Submission status: Time Limit Exceeded

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

ans = N
for i in range(N + 1):
    left_num = S[:i].count('#')
    right_num = S[i:].count('.')
    ans = min(ans, (left_num + right_num))
    if right_num == 0:
        break
print(ans)

Submission status: Time Limit Exceeded

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

result = int(n)
sum_cnt= int(n)
for i in range(len(s)+1):
    sum_cnt = s[:i].count("#") + s[i:].count(".")
    result = min(sum_cnt,result)
print(result)

Submission status: Time Limit Exceeded

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

ans = N
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()
sr = s[::-1]

if s == "." * n or s == "#" * n:
    print(0)
else:
    ans = n
    for i in range(n):
        num = s[:i].count("#") + s[i:].count(".")
        ans = min(num, ans)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def countc(color,num):
  cnt=0
  if color=='#':
    for i in range(num):
      if S[i]=='#':
        cnt+=1
  else:
    for j in range(num,N):
      if S[j]=='.':
        cnt+=1
  return cnt


import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
c=N*2
for i in range(N+1):
  c = min(c,countc('#',i)+countc('.',i))
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
c=N
for i in range(N+1):
  c = min(c,S[:i].count('#')+S[i:].count("."))
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
c=N*2
for i in range(N+1):
  c = min(c,S[:i].count('#')+S[i:].count("."))
print(c)

Submission status: Time Limit Exceeded

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

if '.' not in S or '#' not in S:
  print(0)
  sys.exit()
  
ans = N
for i in range(N):
  ans = min(S[:i].count('#') + S[i:].count('.'), ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#S=input()
#import fractions
#lis=list(map(int,input().split()))

n=int(input())
s=input()
ans=n
wtb,btw=0,0
for i in range(n-1):
    for j in range(i+1):
        if s[j]=="#":
            btw+=1
    for j in range(i+1,n):
        if s[j]==".":
            wtb+=1
    tmp=wtb+btw
    if ans>tmp:
        ans=tmp
count=0
for i in range(n):
    if s[i]=="#":
        count+=1
wtb=n-count
btw=count
m=min(wtb,btw)
if ans>m:
    ans=m

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().rstrip('#').lstrip('.')
#intS = []
def xor(A,B):
    #print(A)
    #print(B)
    num = 0
    for i in range(len(A)):
        
        if A[i]!=B[i] :
            num = num + 1
    return num
# for s in S :
#     intS.append(0 if s=='.' else 1)
minC = N

mask = ['#' for j in range(len(S) + 1)]
for i in range(len(S) + 1):
    mask[i] = '.'
    c = xor(mask[1::],S)
    if c < minC:
        minC = c

print(minC)
# def dl(_S):
    

#     l = '.'
#     r = '#'
    
#     _S = _S.lstrip(l).rstrip(r)
#     print(_S)
#     if len(_S) == 0:
#         return 0
#     _S2W = _S.lstrip(r)
#     _S2B = _S.rstrip(l)
#     _S2 =  _S2W if len(_S2W) <= len(_S2B) else _S2B
#     return len(_S) - len(_S2) + dl(_S2)
# print(dl(S))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().rstrip('#').lstrip('.')
intS = []
def xor(A,B):
    #print(A)
    #print(B)
    num = 0
    for a,b in zip(A,B):
        if a^b :
            num = num + 1
    return num
for s in S :
    intS.append(0 if s=='.' else 1)
minC = N

mask = [1 for j in range(len(intS) + 2)]
for i in range(len(intS) + 2):
    mask[i] = 0
    c = xor(mask[1::],intS)
    if c < minC:
        minC = c

print(minC)
# def dl(_S):
    

#     l = '.'
#     r = '#'
    
#     _S = _S.lstrip(l).rstrip(r)
#     print(_S)
#     if len(_S) == 0:
#         return 0
#     _S2W = _S.lstrip(r)
#     _S2B = _S.rstrip(l)
#     _S2 =  _S2W if len(_S2W) <= len(_S2B) else _S2B
#     return len(_S) - len(_S2) + dl(_S2)
# print(dl(S))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
S = [0 if si == "#" else 1 for si in S]
def taskC(N,S):
    Wlist = []
    Blist = []
    Wcount = 0
    Bcount = 0
    S0 = S[0]
    for si in S:
        if si == 0:
            Bcount += 1
            if Wcount > 0:
                Wlist = [Wcount] + Wlist
                Wcount = 0
        else:
            Wcount += 1
            if Bcount >0:
                Blist += [Bcount]
                Bcount = 0
    Wlist = ([Wcount] + Wlist) if Wcount > 0 else Wlist
    Blist = (Blist + [Bcount]) if Bcount > 0 else Blist
    if len(Wlist)+len(Blist) <= 1:
        return 0
    if len(Wlist)>len(Blist):
        Wlist = Wlist[:-1]
        S0 = 0
    elif len(Blist)>len(Wlist):
        Blist = Blist[:-1]
        S0 = 0
    Wsum = [0]
    Bsum = [0]
    for ind in range(len(Wlist)):
        Wsum = [ Wsum[0] + Wlist[ind]] + Wsum
        Bsum += [ Bsum[-1] + Blist[ind]]
    ret = min([Wsum[i]+Bsum[i] for i in range(len(Wsum))])
    if S0 == 0:
        ret2 = min([Wsum[i]+Bsum[i+1] for i in range(len(Wsum)-1)])
        return min(ret, ret2)
    else:
        ret2 = min([Wsum[i+1]+Bsum[i] for i in range(len(Wsum)-1)])
        return min(ret, ret2)
print(taskC(N,S))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().rstrip('#').lstrip('.')
intS = []
def xor(A,B):
    #print(A)
    #print(B)
    num = 0
    for a,b in zip(A,B):
        if a^b :
            num = num + 1
    return num
for s in S :
    intS.append(0 if s=='.' else 1)
minC = N

for i in range(len(intS) + 1):
    tmp = [0 for j in range(i)]
    tmp2 = [1 for k in range(len(intS)+1-i)]
    #print(tmp,tmp2)
    tmp = tmp + tmp2
    c = xor(tmp,intS)
    if c < minC:
        minC = c

print(minC)
# def dl(_S):
    

#     l = '.'
#     r = '#'
    
#     _S = _S.lstrip(l).rstrip(r)
#     print(_S)
#     if len(_S) == 0:
#         return 0
#     _S2W = _S.lstrip(r)
#     _S2B = _S.rstrip(l)
#     _S2 =  _S2W if len(_S2W) <= len(_S2B) else _S2B
#     return len(_S) - len(_S2) + dl(_S2)
# print(dl(S))

Submission status: Time Limit Exceeded

Solution code:
n = int(input());s = input()
ans = [s.count("."),s.count("#")]
for i in range(n): ans.append(s[:i-1].count("#")+s[i:].count("."))
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
g = int(input())
h = input()

count_list = []
for i in range(0, g+1):
    count_list.append(h[:i].count('#') + h[i:].count('.'))
print(min(count_list))

Submission status: Time Limit Exceeded

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

frac = []
for i in range(n+1):
	sum_loss = stones[:i].count("#") + stones[i:].count(".")
	frac.append(sum_loss)
print(min(frac))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()                                                                                                                                                                                                                                                                                                                                                                                                                                            
list_S = list(S)
N1 = 0

ans_list = []
for color in list_S:
    list_S1 = list_S[N1:]
    list_S2 = list_S[:N1]
    ans = list_S2.count('#') + list_S1.count('.')
    ans_list.append(ans)
    N1 += 1
ans_list.append(list_S.count("#"))
     
print(min(ans_list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
t=s.count("#")
for i in s:
    if i=="#": t-=1
    else: t+=1
    t=min(t,s.count("#"))
print(t)

Submission status: Time Limit Exceeded

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

white = 0
black = 0
ans = None

for i in range(N):
  white = S[0:i].count("#")
  black = S[i+1:N+1].count(".")
  if ans == None:
    ans = white+black
  else:
    ans = min(ans,white+black)

print(ans)

Submission status: Time Limit Exceeded

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

white = 0
black = 0
index = 0

ans = []

for i in range(N):
  white = S[0:i].count("#")
  black = S[i+1:N+1].count(".")
  ans.append(white+black)

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
b = 0
w = 0
for i in range(n):
    if s[i] == '#':
        tmp = s[i+1:].count('.')
        if tmp > b:
            b = tmp
    else:
        tmp = s[:i].count('#')
        if tmp > w:
            w = tmp
print(min(b,w))

Submission status: Time Limit Exceeded

Solution code:

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

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

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

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

    return min(w_b,allb,allw)

print(search(n,s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(input())
b=100000
tmp=100000

for i in range(1,n):
  if (a[i]=="#" and a[i-1]=="."):
  	tmp=a[:i].count("#")+a[i:].count(".")
  if tmp<b:
    b=tmp
      
print(min(b,a.count("."),a.count("#")))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input() + 'a'

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
count=0
if "#" not in s or "." not in s:
    print(0)
else:
    for i in range(n-1):
        if s[i]=="#" and s[i+1]==".":
            s.pop(i+1)
            s.insert(i+1,"#")
            count+=1
    print(count)

Submission status: Time Limit Exceeded

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

S_map = [1 if i=="." else 0 for i in S]
ans = []

for i in range(N+1):
    if(i == 0 or i == N or S[i-1] != S[i]):
        if(i != 0):
            left_white = sum(S_map[:i])
            left_black = i - left_white
        else:
            left_white = 0
            left_black = 0
        if(i != N):
            right_white = sum(S_map[i:])
            right_black = (N - i) - right_white
        else:
            right_white = 0
            right_black = 0
        ans.append(min(left_white+right_white, left_black+right_black, left_black+right_white))
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
S_list = list(S)
i = 0
count = 0
for i in range(N-1):
    if S_list.count("#") >= S_list.count("."):
        if(S_list[i] == "#" and S_list[i+1] == "."):
            S_list[i+1] = "#"
            count += 1
            i += 1
        else:
            i += 1
    else:
        if(S_list[i] == "#" and S_list[i+1] == "."):
            S_list[i+1] = "."
            count += 1
            i += 1
        else:
            i += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(input())
b=[]

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

b.append(a.count("."))
b.append(a.count("#"))

print(min(b))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()
count = []
siro_kuro = 10000000
kuro_siro = 10000000
for i in range(N):
#    print('i: ' + str(i))
    if S[i]=='#':
        kuro_siro = S[0:i].count('#')
#        print(kuro_siro)
        siro_kuro = S[i:N+1].count('.')
#        print(siro_kuro)

    count.append(kuro_siro+siro_kuro)
#    print()

m = min(count)
if m == 20000000: m = 0

print(m)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

ans=[]
for i in xrange(0,n):
    ans.append(-1)
ans[0]=0

for i in xrange(1,n):
    if s[i] == ".":
        ans[i] = min(s[:i].count("#"), ans[i-1]+1)
    else:
        ans[i] = min(ans[i-1], s[:i].count("#")+1)

print ans[n-1]

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

ans=[]
for i in range(0,n):
    ans.append(-1)
ans[0]=0

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

print ans[n-1]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = N
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()
sl=list(s)

c=0
b=0
w=0
res=2*10^5
for i in range(n-1):
	b = sl[:i].count("#")
	w = sl[i+1:].count(".")
	c = b + w
	#print(c)
	if c < res:
		res = c

if sl.count("#")==n or sl.count(".")==n:
	res = 0

print(res)