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()
l = []
c = 0
ans = 10**6

if s.count("#")==0:
    print(0)
else:
    for i in range(N):
        if s[i] == "#":
            l.append(c + s[i:N+1].count("."))
            c += 1
    print(min(l))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
print(min(sum(s[j] == '#' if j < i else s[j] == '.' for j in range(n)) for i in range(n+1)))

Submission status: Time Limit Exceeded

Solution code:
def c_stones(N, S):
    import itertools
    if S.count('#') == 0 or S.count('.') == 0:
        return 0
    s = [(k, len(list(v))) for k, v in itertools.groupby(S)]
    ans = float('inf')
    for i in range(len(s)):
        ans1, ans2 = 0, 0
        if s[i][0] == '#':
            # ここから黒にする
            for j in range(len(s)):
                if j < i and s[j][0] == '#':
                    ans1 += s[j][1]
                elif j > i and s[j][0] == '.':
                    ans1 += s[j][1]
        elif s[i][0] == '.':
            # ここまで白にする
            for j in range(len(s)):
                if j < i and s[j][0] == '#':
                    ans1 += s[j][1]
                elif j > i and s[j][0] == '.':
                    ans1 += s[j][1]
        ans = min(ans1, ans)
    return ans

N = int(input())
S = input()
print(c_stones(N, S))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
st = input()
i = 0
b = 0
w = 0
ans = []
a = 0

for i in range(n + 1):
    for j, s in enumerate(st):
        if i <= j and s == '.':
            a += 1
        elif i > j and s == '#':
            a += 1

    ans.append(a)
    a = 0

print(min(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
scnt=s.count("#.")
ans=0
while scnt>0:
    ans+=scnt
    s=s.replace("#.","")
    scnt=s.count("#.")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = S.count(".")
for x in range(N):
    count = S.count("#",0,x) + S.count(".",x+1,N)
    if count < ans:
        ans = count
count = S.count("#")
if count < ans:
    ans = count
print(ans)

Submission status: Time Limit Exceeded

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

if '#' not in S:
    print(0)
else:
    ans = []
    for i in range(N):
        if S[i] == '#':
            ans.append(S[:i].count('#') + S[i:].count('.'))
    else:
        print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input()) #len(list)
list=list(input())
results=[0]
def count_str(list,num,str):
    newlist=list[num+1:]
    return(newlist.count(str))

for i in range(0,N):
    if list[i]=='#':
        results.append(count_str(list,i,'.'))

print(max(results))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
v = []
for i in range(len(s)):
  if s[i] == "#":
    t = s[0:i].count("#")
    u = s[i+1:len(s)].count(".")
    v.append(t+u)
if v==[]:
    v=[0]
print(min(v))

Submission status: Time Limit Exceeded

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

cnt = 0

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

x = 1*10**5


for i in range(n+1):
    b = 0
    w = 0
    for j in range(i):
        if s[j] == "#":
            b = b + 1

    w = n  - i - cnt + b

    x = min(x,b+w)

print(x)

Submission status: Time Limit Exceeded

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

flag = True

if s[0] == '#':
    flag = False
else:
    for i in range(n-1):
        if s[i] == '.' and s[i+1] == '#':
            s = s[i+1:]
            flag = False
            break
if flag == False:
    a = s.count('.')
else:
    a = 0

flag = True

if s1[n-1] == '.':
    flag = False
else:
    for i in range(n-1):
        if s1[n-i-1] == '#' and s1[n-i-2] == '.':
            s1 = s1[:n-i-1]
            flag = False
            break

if flag == False:
    b = s1.count('#')
else:
    b = 0

c = min(a,b)

for i in range(n-1):
    if s2[i] == '.' and s2[i+1] == '#':
        s3 = s[:i+1]
        s4 = s[i+1:]
        d = s3.count('#') + s4.count('.')
        c = min(c,d)


print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
if S.count('#') < S.count('.'):
  ans = S.count('#')
else:
  ans = S.count('.')
for i in range(N):
  tmp = S[:i]
  tmp2 = S[i:]
  A = tmp.count('#')+tmp2.count('.')
  if A<ans:
    ans = A
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
l = []
c = 0
ans = 10**6

if s.count("#")==0:
    print(0)
else:
    for i in range(N):
        if s[i] == "#":
            k = i
            aaa = s[i:N+1].count(".")
            ans = min(c + aaa, ans)
            c += 1
    print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

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

x = 2*10**5


for i in range(n+1):
    b = 0
    w = 0
    for j in range(i):
        if s[j] == "#":
            b = b + 1

    w = n  - i - cnt + b

    x = min(x,b+w)

print(x)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=input()
tmp=N
for i in range(N+1):
    a=s[:i].count("#")
    b=s[i:N].count(".")
    if tmp>a+b:
        tmp=a+b
print(tmp)

Submission status: Time Limit Exceeded

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

X = [0 if x == '#' else 1 for x in S] # 0:black 1:white

ans = N - sum(X)

for i in range(N):
    x = i - sum(X[:i])
    y = sum(X[i:])
    ans = min(x+y, ans)

print(ans)

Submission status: Time Limit Exceeded

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

for j in range(n):
  cnt = 0
  for i in range(j):
    if s[i] != ".":
      cnt += 1
  for i in range(j+1,n):
    if s[i] != "#":
      cnt += 1
  array.append(cnt)
  
  

print(min(array))

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
hoge=input()
flag=hoge[0]
kazu=0
siro=[]
kuro=[]
for i in range(n):
  if(hoge[i]==flag):
    kazu+=1
  else:
    if(flag=="."):
      siro.append(kazu)
      kazu=1
      flag="#"
    else:
      kuro.append(kazu)
      kazu=1
      flag="."
      
if(flag=="."):
  siro.append(kazu)
else:
  kuro.append(kazu)

kuro=kuro[::-1]
ans=[]

ans.append(hoge.count("."))
ans.append(hoge.count("#"))
base=0

if(hoge[0]=="#"):
  base+=kuro[-1]
  kuro=kuro[:len(kuro)-1]
if(hoge[-1]=="."):
  base+=siro[-1]
  siro=siro[:len(siro)-1]

siro=siro[1:]
kuro=kuro[1:]

for i in range(len(siro)+1):
  ans.append(base+sum(siro[:i])+sum(kuro[i:]))
  
print(min(ans))

Submission status: Time Limit Exceeded

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

for i in range(2**N):
  T = ""
  tmp = 0
  sw = False
  for j in range(N):
    if (i >> j) & 1:
      T += "." if S[j] == "#" else "#"
      tmp += 1
    else:
      T += S[j]
  for k in T:
    if k == "#":
      if sw == False:
        sw = True
      else:
        continue
    if k == ".":
      if sw == False:
        continue
      else:
        tmp = N
        break
  ans = min(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 1000000
z = 0
B = S.count('#')
C = S.count('.')
for i in range(N):
  tmp = S[:i]
  tmp2 = S[i:]
  A = tmp.count('#')+tmp2.count('.')
  if A <= B and A <= C:
    z = A
  elif B <= A and B <= C:
    z = B
  else:
    z = C
    
  if z<ans:
    ans = z
print(ans)

Submission status: Time Limit Exceeded

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

sdot = ['']
ssphas = s.split('.')
sspdot = s.split('#')
num = min(s.count('.'),s.count('#') - len(ssphas[-1]))
if s[0] == '.':
    sdot.extend(ssphas)
for i in range(len(ssphas)):
    num = min(len(''.join(ssphas[0:i + 1]) + ''.join(sspdot[i + 1:-1])),num)
print(num)

Submission status: Time Limit Exceeded

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

count = 0

S1 = S
S2 = S

s1_c = 0
s2_c = 0

while 1:
    if "#." in S1:
        S1 = S1.replace("#.", "##",1)
        s1_c = s1_c +1
    else:
        break

while 1:
    if "#." in S2:
        S2 = S2.replace("#.", "..",1)
        s2_c = s2_c +1
    else:
        break




result = min(s1_c, s2_c)


print(result)

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:
import sys
n = int(input())
S = input()

i = S.find('#')
if i < 0:
    print(0)
    sys.exit()

Min = 200000
for j in range(i, n):
    if S[j:j+1] == '#':
        a = S[:j].count('#') 
        b = S[j:n].count('.')
        Min = min(Min, a+b)
        
print(Min)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
A = []

for i in range(N+1):
    x = N-(S[:i].count(".")+S[i:].count("#"))
    A.append(x)

print(min(A))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
count=[0]*(n+1)
for i in range(n+1):
    for j in range(n):
        if j<i:
            if s[j]=='#':
                count[i]+=1
        else:
            if s[j]=='.':
                count[i]+=1
print(min(count))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cmp1,cmp2 = 0,0
i = 0
if s.count('.') == n:
    print('0')
else:
    cmp1 = s[s.index('#'):].count('.')
    while s[i:].count('.') != 0:
        if s[i] == '#':
            cmp2 += 1
        i += 1
    print(min(cmp1,cmp2))

Submission status: Time Limit Exceeded

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

ret = n
for i in range(n+1):
  ss = '.' * (n-i) + '#' * i
  cnt = 0
  for j in range(n):
    if s[j] != ss[j]:
      cnt += 1
  if ret > cnt:
    ret = cnt
print(ret)

Submission status: Time Limit Exceeded

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

min_cost = n

for i in range(n+1):
    s_left = s[:i]
    s_right = s[i:]
    cost = s_left.count('#') + s_right.count('.')
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Submission status: Time Limit Exceeded

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

A = np.zeros(N+1)
for i,s in enumerate(S):
    if s=='.':
        A[-i-1:] += 1
    else:
        A[:N-i] += 1

print(int(np.min(A)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
S=S+'9'
ans=0
for i in range(N):
    if S[i]=='#' and S[i+1]=='.':
        cntj=0
        for j in range(i,-1,-1):
            if S[j]=='#':
                cntj+=1
            else:
                break
        cntk=0
        for k in range(i+1,N+1):
            if S[k]=='.':
                cntk+=1
            else:
                break
        if cntj >= cntk:
            ans += cntk
            S = S[:i+1]+'#'*cntk+S[i+cntk+1:]
        else:
            ans += cntj
            S = S[:i-cntj+1]+'.'*cntj+S[i+1:]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
S = S.replace('.', '1').replace('#', '0')
white = S.count(".")
#checker = 
intS = int(S,2)
check =int('1'*N,2)
min_change = N
for i in range(N+1):
    change = bin(check^intS)[2:].count('1')
    if min_change > change:
        min_change = change
    check = check & ~pow(2, i)
print(min_change)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 1000000
z = 0
for i in range(N):
  tmp = S[:i]
  tmp2 = S[i:]
  A = tmp.count('#')+tmp2.count('.')
  B = tmp.count('#')+tmp2.count('#')
  C = tmp.count('.')+tmp2.count('.')
  if A <= B and A <= C:
    z = A
  elif B <= A and B <= C:
    z = B
  else:
    z = C
    
  if z<ans:
    ans = z
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
SS = list(S)
 
D = 0
 
black = S.split("#")
white = S.split(".")

if S[0] == ".":
  black.pop(0)
 
if S[-1] == "#":
  white.pop()
    
while "" in black:
  black.remove("")
  
while "" in white:
  white.remove("")
  
for b, i in zip(black,white):
  D += min(len(b),len(i))
  
print(D)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
 
 
S2 = ''.join(S.split("#")[1:])
S3 = ''.join(S.split(".")[:-1])
if S2 == S:
        print("0")
else:
    sn = S2.count(".")
    sn3 = S3.count("#")
    co = N
    for i in range (N):
        tco = S[:N].count("#") + S[N:].count(".")
        if co > tco:
            co = tco
    print(min(co,sn,sn3))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
 
#最終的な白の数は0からN
#白が左からt個、以降黒がT-t個
R=[]
#countが遅い？とすれば、Sumで出せるように数値にすると早いかも
T=[]
for i in range(N):
  if S[i]=='.':
    T.append(0)
  else:
    T.append(1)

for i in range(N+1):
  #R.append(S[0:i].count('#')+S[i:N].count('.'))
  R.append(sum(T[0:i])+((N-i)-sum(T[i:N])))
print(min(R))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
mini=len(s)
if ("#" in s )and("." in s):
  for i in range(len(s)+1):
    a=s[0:i].count("#")+s[i:len(s)].count(".")
    if a<mini:
      mini=a
  print(mini)
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
def solve():
  n = int(input())
  s = input()
 
  ans = 10**15
  for i in range(n+1):
   s1 = s[0:i]
   s2 = s[i::]
   tp = s1.count('#')
   tp2 = s2.count(".")
   ans = min(ans,tp+tp2)
  print(ans)
solve()

Submission status: Time Limit Exceeded

Solution code:
import re
N = int(input())
S = input()
ans=2*10**5

l = []
for i in range(len(S)):
    if S[i] == "#":
        l.append(i)


if S.count("#") == 0 or S.count(".") == 0:
    print(0)

else:
    for i in l:
        a = S[i+1:].count(".")+S[:i].count("#")
        ans = min(a,ans)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def get_cost_change_black(S):
    return S.count(".")

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

indexs = [i for i, x in enumerate(S) if x == "#"]
if len(indexs) == 0:
    print(0)
else:
    answer = 10000000
    change_white = 0
    for i in indexs:
        x = change_white + get_cost_change_black(S[i:])
        if x < answer:
            answer = x
        change_white = change_white + 1
        if change_white >= x:
            break
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
list = [0]*N

for i in range(N-1):
    list[i+1] = 1 if S[i:i+2] == '#.' else 0

for i in range(N-1):
    if list[i] == 1 and (S[:i-1].count('.') == len(S[:i-1])):
        list[i-1] = 1
        list[i] = 0
    elif list[i] == 1 and S[i+1] == '.':
        list[i+1] = 1

print(sum(list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
def check(N, S):
    ls = []
    for i in range(N - 1):
        if S[i] == "#" and S[i + 1] == ".":
                ls.append(True)
        else:
            ls.append(False)
    return ls.count(True)

def change(N, S):
    cnts = []
    for i in range( N):
        form = S[:i]
        latt = S[i:]
        cnt = 0
        if form.count(".") >= form.count("#"):
            cnt += form.count("#")
        if form.count(".") < form.count("#"):
            cnt += form.count(".")
        cnt += latt.count(".")
        cnts.append(cnt)
    return cnts

if check(N,S) == 0:
    print(0)
else:
    print(min(change(N, S)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
if all([v == '.' for v in s]):
    print(0)
else:
    r = 0
    s = s[s.find('#'):]
    while (True):
        k = s.find('.#') + 1
        if k == 0:
            r += min(s.count('.'), s.count('#'))
            break
        else:
            t = s[:k]
            r += min(t.count('.'), t.count('#'))
            s = s[k:]
    print(r)

Submission status: Time Limit Exceeded

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

ans = 0
while s.find('#.') != -1:
    pos = s.find('#.')
    try:
        if s[pos-1] == '#':
            s = s[:pos] + '##' + s[pos+2:]
        elif s[pos+2] == '.':
            s = s[:pos] + '..' + s[pos+2:]
        elif s[pos-2:pos] == '#.':
            s = s[:pos] + '##' + s[pos+2:]
        elif s[pos+2:pos+4] == '#.':
            s = s[:pos] + '..' + s[pos+2:]
        else:
            s = s[:pos] + '##' + s[pos+2:]
        ans += 1
    except:
        a = 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = N

for i in range(N+1):
    whiteprint = S[0:i].count("#")
    blackprint = S[i:N].count(".")

    ans = min(ans,blackprint + whiteprint)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
min_cnt = min(s.count('#'),s.count('.'))
flag = True
cnt = 0
while flag:
    #両端のいらないのを消す
    s = s.lstrip(".")
    s = s.rstrip("#")
    if s =="":
        break
    tmp_cnt = 0
    s = [i for i in s]
    while True:
        if s[0] == "#":
            tmp_cnt += 1
            del s[0]
        else:
            s = ''.join(s)
            break
    if s.count('#') == 0:
        if tmp_cnt >= len(s):
            cnt += len(s)
            break
        else:
            cnt += tmp_cnt
            break
    else:
        s = [i for i in s]
        while True:
            if s[-1] == ".":
                tmp_cnt += 1
                del s[-1]
            else:
                s = ''.join(s)
                break
        cnt += tmp_cnt

print(min(cnt,min_cnt))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
# 文字列の入力
N = int(input())
S_tmp = np.array(list(input()))
S=[]
for i in S_tmp:
    if i == ".":
        S.append(True)
    else:
        S.append(False)
minimum = []
for i in range(0,len(S)+1):
    str1 = [True]*i
    str2 = [False]*(len(S)-i)
    str3 = str1 + str2
    str3 = np.array(str3)
    x = str3==S
    minimum.append(np.sum(x==False))
print(np.min(minimum))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
end = len(s) -1

s1 = s[:]
i = 0
ans1 = 0
while(i < end):
    if s1[i] == '.':
        continue
    c = s1[i] + s1[i+1]
    if c == '#.':
        j = 0
        s1 = s1[:i+1] + '#' + s1[i+2:]
        ans1 = ans1+ 1
    i += 1
print(ans1)

Submission status: Time Limit Exceeded

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

count = 0


for i in range(len(S)):
    if  i != len(S)-1:
        if S[i] == "#" and S[i+1] == ".":
            count = count +1
            if i == 0:
                S = "." + S[i+1:]
            elif i == len(S) - 2:
                S = S[:i+1] + '#'

            elif S[i-1] == "#":
                S = S[:i+1] + '#' + S[i+2:]
            elif S[i-1] == ".":
                S = S[:i] + "." + S[i+1:]

print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
N = int(input())
S = input()
ans=2*10**5


if S.count("#") == 0 or S.count(".") == 0:
    print(0)

else:
    for i in range(len(S)):
        a = S[i+1:].count(".")+S[:i].count("#")
        ans = min(a,ans)
    print(ans)

Submission status: Time Limit Exceeded

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

  ans = 10**15
  a = s.count(".")
  b = s.count("#")
  for i in range(n+1):
   s1 = s[0:i]
   s2 = s[i::]
   tp = s1.count('#')
   tp2 = s2.count(".")
   ans = min(ans,tp+tp2)
  print(ans)
solve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cs = []
for i in range(n+1):
    c=0
    for k in range(n):
        if (i <= k and s[k] != '#') or (k < i and s[k] != '.'):
                c += 1
    cs += [c]
print(min(cs))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
temp = []
temp2 = []
c = 0
pitem = ''
s2 = s + 'a'
for item in s2:
    if pitem == '' or item == pitem:
        c += 1
        pitem = item
    if item != pitem:
        temp.append(c)
        temp2.append(pitem)
        c = 1
        pitem = item
        continue

# print(temp)
# print(temp2)

ck = [0]
cs = [0]
c = 0
for i in range(len(temp2)):
    if temp2[i] == '#':
        c += temp[i]
    cs.append(c)
c = 0

for i in range(len(temp2))[::-1]:
    if temp2[i] == '.':
        c +=  temp[i]
    ck.insert(0, c)
ck.insert(0, 0)

cost = [cs[i] + ck[i+1] for i in range(len(temp2)+1)]

print(min(cost))

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()
 
#最終的な白の数は0からN
#白が左からt個、以降黒がT-t個
#R=[]
res=N
for i in range(N+1):
  #R.append(S[0:i].count('#')+S[i:N].count('.'))
  dmy = S[0:i].count('#')+S[i:N].count('.')
  if dmy<res:
    res=dmy
print(res)

Submission status: Time Limit Exceeded

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

x = 2*10**5

for i in range(n+1):
    b = 0
    w = 0
    for j in range(i):
        if s[j] == "#":
            b = b + 1

    for j in range(i,n):
        if s[j] == ".":
            w = w + 1

    x = min(x,b+w)

print(x)

Submission status: Time Limit Exceeded

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

ans=99999999
for i in range(len(S)+1):
    temp = S[:i].count('#') + S[i:].count('.')
    ans = min(temp, ans)
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
p=[]
m=0
x=s.count("#.")
c=s.count("#.")
while x>0:
    x=s.count("#.")
    s=s.replace("#.","..",1)
    m+=x
    x=s.count("#.")
    if x==0:
        p.append(m)
p.append(c)
print(min(p))

Submission status: Time Limit Exceeded

Solution code:
def get_cost_change_black(S):
    return S.count(".")

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

indexs = [i for i, x in enumerate(S) if x == "#"]
if len(indexs) == 0:
    print(0)
else:
    answer = 10000000
    change_white = 0
    for i in indexs:
        x = change_white + get_cost_change_black(S[i:])
        if x < answer:
            answer = x
        change_white = change_white + 1
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ssp = s.split('.')
num = min(s.count('.'),s.count('#') - len(ssp[-1]))
if s.count('#') == 0 or s.count('.') == 0:
    print(0)
    exit()
for i in range(n):
    if s[i - 1] == s[i]:
        continue
    num = min(num,s[:i].count('#') + s[i:].count('.'))
print(num)

Submission status: Time Limit Exceeded

Solution code:
N=int(input()) #len(list)
list=list(input())
results=[0]
def count_str(list,num,str):
    count=0
    for i in range(num+1,len(list)):
        if list[i]==str:
            count+=1
    return count


a=0
for i in range(0,N):
    if list[i]=='#':
        results.append(count_str(list,i,'.'))

print(max(results))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
S = input()
S = S.replace('.', '0').replace('#', '1')
b = np.array(list(S)).astype(np.int)
w = np.ones(N, dtype=np.int) - b

moves = 200000

for i in range(N + 1):
    left = np.sum(b[:i])
    right = np.sum(w[i:])
    moves = np.min([moves, left + right])

print(moves)

Submission status: Time Limit Exceeded

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

sl = []
for i in range(n):
    sl += s[i]

cs = []
l = ['.']*n
for i in range(n+1):
    c=0
    for k in range(n):
        if i <= k and sl[k] != '#':
                c += 1
        elif k < i and sl[k] != '.':
                c += 1
    cs += [c]
print(min(cs))

Submission status: Time Limit Exceeded

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

min = n

for i in range(n):

    bl = s[0:i].count('#')
    wr = s[i + 1:n].count('.')

    if min > wr + bl:
        min = wr + bl


print(min)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=n
for i in range(0,n+1):
    cw=s[:i].count('#')
    cb=s[i:].count('.')
    if ans>=cw+cb:
        ans=cw+cb
print(ans)

Submission status: Time Limit Exceeded

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

if S.count("#") == 0 or S.count(".") == 0:
    print(0)

else:
    for i in S:
        a = S[S.find("#"):].count(".")+S[:S.find("#")].count("#")
        ans = min(a,ans)
    print(ans)

Submission status: Time Limit Exceeded

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

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

min_turn_stones = 2*10**5

for i in range(trial_num):
    tmp_min = stones[:i].count("#") + stones[i+1:].count(".")
    if( tmp_min < min_turn_stones):
        min_turn_stones = tmp_min

print(min_turn_stones)

Submission status: Time Limit Exceeded

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

N = int(input())
S = str(input())
Sarray = list(S)
Sarraynum = []

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

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

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


print(a)

Submission status: Time Limit Exceeded

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

ans = 0
for i, s in enumerate(S):
    if i == N-1:
        break
    if s is '#':
        ans__ = 0
        flag = -1
        count = i
        for s_ in S[count+1:]:
            if count + 1 == N or s_ is '#':
                break
            if s_ is '.' :
                flag = 1
                ans__ += 1
        if flag == 1:
            ans_ = 1
            c = i
            while c >= 1:
                if S[c-1] is '#':
                    ans_ += 1
                c -= 1
            ans += min(ans_, ans__)

print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
z = 0
if N == 1:
    print("0")
    exit()
else:
    for i in range(N-1):
        x = S[i]
        y = S[i+1]
        if x == "#":
            if y == ".":
                cnt += 1
                S = S[0:i+1] + "#" + S[i+2:N]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
d = n - s[::-1].find('.') - 1
c = s[:d].count('#')
d2 = s.find('#')
c2 = s[d2:].count('.')
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:
import sys

def parse(inp):
    n=int(next(inp))
    s=list(next(inp))
    
    b=0
    for i in range(n-1,-1,-1):
        b=b<<1
        if(s[i]=="."): b+=1        
#     print(bin(b))    
    return n,b
  
def main(inp):
    n,b=inp
    
    std=0
    ans=n
    for i in range(n+1):
        ans=min(ans,bin(std^b).count("1"))
        std=(std<<1)+1
        
    return ans
  
print(main(parse(sys.stdin)))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

N = int(input())
S = input().strip()

def stone_cnt(idx):
  return S[:idx].count("#") + S[idx:].count(".")

left = 0
right = len(S)

ans = min([stone_cnt(i) for i in range(N+1)])
  

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N = makeInt(input_string[0])
    S = input_string[1].rstrip()
    if len(S) == 1:
        return 0
    if S == "#.":
        return 1
    S = list("."+S)
    w = "."
    b = "#"
    c = 0
    for i in range(N):
        if S[i] == w and S[i-1] == b:
            b_c = 0
            w_c = 0
            for j in range(i, N+1):
                if S[j] == w:
                    w_c += 1
                else:
                    break
            for k in range(0, i)[::-1]:
                if S[k] == b:
                    b_c += 1
                else:
                    break
            #print(w_c)
            #print(b_c)
            if w_c > b_c:
                for h in range(0, i)[::-1]:
                    if S[h] == b:
                        S[h] = w
                        c += 1
                    else:
                        break
        if S[i] == b:
            if S[i-1] == w and S[i+1] == w:
                S[i] = w
                c += 1
                continue
        if i > 0 and S[i] == w:
            #print(S)
            #print(S[i])
            if S[i-1] == b:
                S[i] = b
                c += 1
        if i > 0 and S[i] == w:
            #print(S)
            #print(S[i])
            if S[i-1] == b:
                S[i] = b
                c += 1
    i = N
    if i == N:
        #print("a")
        #print(S)
        #print(S[i])
        if S[i-1] == b and S[i] == w:
            S[i] = b
            c += 1
    return c


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
end = len(s) -1

s1 = s[:]
i = 0
ans1 = 0
while(i < end):
    c = s1[i] + s1[i+1]
    if c == '#.':
        s1 = s1[:i+1] + '#' + s1[i+2:]
        ans1 = ans1+ 1
    i += 1
print(ans1)

Submission status: Time Limit Exceeded

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