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

Solution code:
n = int(input())
S = input()
x, y, c = 0, S.count('.'), min(n-y, y)
for i in range(n):
  t = S[i]=='#'
  x += t
  y -= 1-t
  c = min(c, x+y)
print(c)

Submission status: Runtime Error

Solution code:
_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)

x = 0
y = S.count('.')
c = min(n-y, y)
for i in range(n):
  t = S[i]=='#':
  x += t
  y -= not t
  c = min(c, x+y)
print(c)

Submission status: Runtime Error

Solution code:
_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)

x = 0
y = S.count('.')
c = min(n-y, y)
for i in range(n):
  t = S[i]=='#':
  x += t
  y -= ~t
  c = min(c, x+y)
print(c)

Submission status: Runtime Error

Solution code:
_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)

x = 0
y = S.count('.')
c = min(n-y, y)
for i in range(n):
  if S[i] == '#':
    x += 1
  else:
    y -= 1
  c = min(ans, x+y)
print(c)

Submission status: Runtime Error

Solution code:
_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)

x = 0
y = S.count('.')
c = min(n-y, y)
for i in range(n):
  t = S[i]=='#':
  x += t
  y -= t
  c = min(c, x+y)
print(c)

Submission status: Runtime Error

Solution code:
N,S = open(0).read().split()
N=int(N)
S=list(S)

def calc():
    group = [] if S[0] == '.' else [0]
    n = 0
    mark = S[0]
    for s in S:
        if s == mark:
            n += 1
        else:
            mark = s
            group.append(n)
            n = 1
    if n > 0:
        group.append(n)
    if S[-1] == '#':
        group.pop()

    cnt = 0
    i = 1
    j = len(group) - 1
    while i <= j:
        l = group[i]
        r = group[j]
        if l < r:
            cnt += l
            i += 2
        else:
            cnt += r
            j -= 2
    return cnt

all_w = sum([1 if s == '#' else 0 for s in S])
all_b = sum([1 if s == '.' else 0 for s in S])
lwrb = calc()
print(min(all_w, all_b, lwrb)

Submission status: Runtime Error

Solution code:
n=int(input())
c=input()
b=c.count("#")
w=c.count(".")

cnt=0
for i in range(w):
  if c[i]=="#":
    cnt+=1
  bb=b-cnt
  ww=w-cnt

ans=min(ww+cnt,b,w)
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    S = input()
    B = []
    W = []
    i = 0
    fin = None
    while i < N:
        if S[i] == '#':
            if i == N-1:
                B.append(1)
                fin = True
            else:
                tmp = 1
                while S[i+1] == '#':
                    tmp += 1
                    i += 1
                    if i == N-1:
                        break
                B.append(tmp)
        else:
            if i == N-1:
                W.append(1)
                fin = False
            else:
                tmp = 1
                while S[i+1] == '.':
                    tmp += 1
                    i += 1
                    if i == N-1:
                        break
                W.append(tmp)
        i += 1

    # print(B,W)
    ans = sum(B)
    L = len(B)+len(W)
    now = ans
    if fin:
        for i in range(L):
            if i % 2 == 0:
                now -= B[i//2]
            else:
                now += W[i//2]
            ans = min(ans,now)
    else:
        for i in range(L):
            if i % 2 == 1:
                now -= B[i//2]
            else:
                now += W[i//2]
            ans = min(ans,now)
    print(ans)



    

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll T;cin>>T;while(T--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void solve(){
    int n,ans=200001;
    cin>>n;
    string s;
    cin>>s;
    int dp[n+1][2];
    memset(dp,0,sizeof dp);
    for(int i=1;i<=n;i++){
        dp[i][0]=dp[i-1][0];
        dp[i][1]=dp[i-1][1];
        if(s[i-1]=='.') dp[i][0]++;
        else dp[i][1]++;
    }
    for(int i=1;i<=n;i++){
        if(s[i-1]=='.') ans=min(ans,dp[i-1][1]+dp[n][0]-dp[i-1][0]);
    }
    if(ans==200001) cout<<0;
    else cout<<ans-1;
    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
n = int(input())
s = list(map(str, input().rstrip()))

if s.count("#") == 0 or s.count(".") == 0:
    print(0)
    sys.exit()

s = np.array([x == "#" for x in s])

dp = np.zeros([2, n], dtype=int)

# dp0は黒の数、dp0は白の数
dp[0] = s
dp[1] = ~s

dp = dp.cumsum(axis=1)

# 白の数は「それ以降の」と読み替える
dp[1] = dp[1].max() - dp[1]

print((min(dp[0] + dp[1]).min(), s.count("#"), s.count("."))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
cou = 0
if "#" not in s:
  print(0)
else:
  a = s.index("#")
  s_r = s[::-1]
  a1 = s_r.index(".")
  a3 = n-a1
  s1 = s[a:a3]
  b = s1.count(".")
  c = s1.count("#")
  print(min(b,c))

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
while s[-1] == "#":
    s.pop()
s = "".join(s)
n = len(s)
data = []
ind = []
cnt = 0
ans = 0
for i in range(n):
    if s[i] == "#":
        cnt += 1
        ind.append(i)
    data.append(cnt)
if not ind:
    print(0)
    exit()
for i in ind:
    m = data[-1]-data[i]+1
    l = n-m-i
    if l > m:
        ans += 1
    else:
        print(ans+l)
        break
else:
    print(ans)

Submission status: Runtime Error

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

if N==1:
  print(0)
  exit()
else:
  W=[1 if S[0]=="." else 0]
  ans=float("inf")

  for i in range(1,N):
    if S[i]==".":
      W.append(W[-1]+1)
    else:
      W.append(W[-1])
      
  if W[-1]==0 or W[-1]==N:
    print(0)
    eixt()

  for i in range(N):
    cost_W = i+1-W[i]
    cost_B = W[-1]-W[i]
    cost=cost_W+cost_B
    #print(N, W[-1], i+1, W[i])
    #print("cost_W:",cost_W,"cost_B:",cost_B,"Total",cost)
    ans=min(ans,cost)
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
b = 0
w = s.count(".")
l = [w]
for i in range(1, n + 1):
    if s[i - 1] == "#":
        b += 1
    if s[i - 1] == ".":
        w -= 1
    l.append(b + w)
    print(l)
print(min(l))

Submission status: Runtime Error

Solution code:
"""
#の右に.が無いようにしたい
一番左にある#.もしくは一番右にある#の部分
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
s = readline().rstrip().decode('utf-8')
ans = 10**9
res = 0
for i in range(n-1):
    if s[i] == "#":
        if s[i+1] == ".":
            res = i
            break

ans = min(ans,s[i:].count("."))

ans = min(ans,s.count("#"),s.count("."))

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
l = []
b = 0
w = s.count(".")
for i in range(1, n - 1):
    if s[i - 1] == "#":
        b += 1
    elif s[i + 1] == ".":
        w -= 1
    l.append(b + w)
print(min(l))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
l = []
b = 0
w = s.count(".")
for i in range(n):
    if s[i] == "#":
        b += 1
    elif s[i] == ".":
        w -= 1
        l.append(b + w)
print(min(l))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
b_total = 0
w_total = 0
ans = 0
for i in range(n):
  if s[i] == '#':
    b_cnt += 1
  if s[i] == '.':
    w_cnt += 1
b_cnt = 0
w_cnt = 0
ans = 10**6
for i in range(n):
  if s[i] == '#':
    b_cnt += 1
  if s[i] == '.':
    w_cnt += 1
  cnt = b_cnt + (w_total - w_cnt)
  ans = min(ans, cnt)
print(ans)

Submission status: Runtime Error

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

S = list(S)
white_count = S.count(".")
black_count = S.count("#")
count = 0

if white_count < black_count:

    for i in range(len(S)-1):
        print(S[i],S[i+1])
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] = "#"
else :
    S = reversed(S)
    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i] =  "."

print(count)

Submission status: Runtime Error

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

Solution code:
# 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: Runtime Error

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

S = list(S)
white_count = S.count(".")
black_count = S.count("#")
count = 0

if white_count < black_count:

    for i in range(len(S)-1):
        print(S[i],S[i+1])
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] = "#"
else :
    S = reversed(S)
    for i in reversed(range(1,len(S))):
        if (S[i]==".")and(S[i-1]=="#"):
            count += 1
            S[i] =  "."

print(count)

Submission status: Runtime Error

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

S = list(S)
white_count = S.count(".")
black_count = S.count("#")
count = 0

if white_count < black_count:

    for i in range(len(S)-1):
        print(S[i],S[i+1])
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] = "#"
else :
    S = reversed(S)
    for i in reversed(range(1,len(S))):
        if (S[i]==".")and(S[i-1]=="."):
            count += 1
            S[i] =  "."

print(count)

Submission status: Runtime Error

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

S = list(S)
white_count = S.count(".")
black_count = S.count("#")
count = 0

if white_count < black_count:

    for i in range(len(S)-1):
        print(S[i],S[i+1])
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] = "#"
else :
    
    for i in reversed(range(1,len(S))):
        if (S[i]==".")and(S[i+1]=="."):
            count += 1
            S[i] =  "."

print(count)

Submission status: Runtime Error

Solution code:
```python

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

S = list(S)
white_count = S.count(".")
black_count = S.count("#")
count = 0

if white_count < black_count:

    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] == "#"
else :
	S = reversed(S)
    for i in reversed(range(len(S)-1)):
      
        if (S[i]=="#")and(S[i-1]=="."):
            count += 1
            S[i] == "."

print(count)
```

Submission status: Runtime Error

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

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

c = Counter(S)
print(max(0, c["#"] - 1))

Submission status: Runtime Error

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

S = list(S)
scount = S.count(".")
kcount = S.count("#")

if scount < kcount:

    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] == "#"
else :
    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i] == "."

print(count)

Submission status: Runtime Error

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

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

c = Counter(S)
print(max(0, c["#"] - 1))

Submission status: Runtime Error

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

c = Counter(S)
print(max(0, c["#"] - 1))

Submission status: Runtime Error

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

S = list(S)
scount = 0
kcount = 0
for i in range(len(S)-1):
    if (S[i]=="#")and(S[i+1]=="."):
        kcount += 1
        S[i+1] == "#"

for i in range(len(S)-1):
    if (S[i]=="#")and(S[i+1]=="."):
        scount += 1
        S[i] == "."

if scount > kcount:
    print(kcount)
else
    print(scount)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
print(min(s[s.find("#"):s.rfind(".")].count("#"),s[s.find("#"):s.rfind(".")+1].count("."))

Submission status: Runtime Error

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

i=0
for ss in s:
  if ss=="#":
    break
  i+=1

s=s[i:]  
  
cnt=0
while s[-1]=="#":
  s=s[:-1]
  if s=="":
    print(0)
    exit()
  
print(min(s.count("."),s.count("#")))

Submission status: Runtime Error

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

i=0
for ss in s:
  if ss=="#":
    break
  i+=1

s=s[i:]  
  
cnt=0
while s[-1]=="#":
  s=s[:-1]
  
print(min(s.count("."),s.count("#")))

Submission status: Runtime Error

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

i=0
for ss in s:
  if ss=="#":
    break
  i+=1

s=s[i:]  
  
cnt=0
for i in range(1,n+1):  
  if s[-1*i]=="#":
    cnt+=1
  else:
    break
if cnt>0:
	s=s[:-1*cnt]
#print(s)
  
print(min(s.count("."),s.count("#")))

Submission status: Runtime Error

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

i=0
for ss in s:
  if ss=="#":
    break
  i+=1

s=s[i:]  
  
cnt=0
for i in range(1,n+1):  
  if s[-1*i]=="#":
    cnt+=1
  else:
    break

s=s[:-1*cnt]
#print(s)
  
print(min(s.count("."),s.count("#")))

Submission status: Runtime Error

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]
        if test == list(sorted(test)[::-1]):
            break
        b = s.rfind(".")
        test[b] = "#"
        countf += 1
        del test[b:len(test)]

    print(countf)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N == 1:
        print(0)
    else:
        S = list(input())

        B = [0] * N
        W = [0] * N

        cntb = 0
        cntw = 0
        for i in range(N):
            if S[i] == '#':
                cntb += 1
                B[i] = cntb
                W[i] = cntw
            else:
                cntw += 1
                B[i] = cntb
                W[i] = cntw
        if cntb == N or cntb == 0:
            print(0)
        else:

            B = [0] + B + B[-1]
            W = [0] + W + W[-1]

            ans = 10 ** 9
            for i in range(1, N + 2):
                ans = min(ans, B[i] + W[-1] - W[i])
            print(ans)


resolve()

Submission status: Runtime Error

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

for i in range(N - 1, -1, -1):
    if S[i] == ".":
        right_white = i
        break

print(min(S.count("."), S[:right_white].count("#")))

Submission status: Runtime Error

Solution code:
n=int(input())
c=str(input())
c=c[::-1]
#print(c)
c_count=[]
count1=0
count2=0
for i in range(n):
    if c[i]=='.':
        start=i
        break
else:
    print(0)


for i in range(start,n):
    if c[i]=='.':
        if count2!=0:
            c_count.append(count2)
            count2=0
        count1+=1
    else:
        if count1!=0:
            c_count.append(count1)
            count1=0
        count2+=1
        
c_count.append(max(count1,count2))

#print(c_count)
ans=0
for i in range(0,len(c_count)-1,2):
    ans+=min(c_count[i],c_count[i+1])
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ans = 0
if s.count('.') != 0:
  white = s.index('.')
  if s.index('.') > 1:
    ans += s.index('.')
  black_num = s.count('#')
  white_num = s.count('.')
print(min(black_num, white_num)+ans)

Submission status: Runtime Error

Solution code:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    _s = "".join(list(reversed(s)))
    if "#" not in s:
        print(0)
    else:
        sind = s.index("#")
        dind = _s.index(".")
        use = s[sind:(N-dind)]
        print(min(use.count("."),use.count("#")))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

a = s.count(".")
b = n-a

i = 0
while s[i]=="."and i>=0:
        a -= 1
        i -= 1
i = n-1
while s[i]=="#"and i<n:
        b -= 1
        i -= 1
print(min(a, b))

Submission status: Runtime Error

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = "."+stdin.readline().rstrip()
kuro = s.count("#")
shiro = n-kuro
mi = shiro
k = 0
sh = shiro
for i in range(n):
    if s[i] == "#":
        k += 1
    else:
        sh -= 1
    mi = min(mi,k+s)
print(mi)

Submission status: Runtime Error

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

black_right, min_val = 0, 2000001
white_left = s.count('.')
ans = []

for moji in s:
    if moji == '.':
        white_left -=1
    else:
        black_right += 1
    ans.append[white_left+black_right]
    #min_val = min(min_val, white_left+black_right)

print(min(ans))

Submission status: Runtime Error

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

black_right, min_val = 0, 2000001
white_left = s.count('.')

for moji in range(s):
    if moji == '.':
        white_left -=1
    else:
        black_right += 1
    min_val = min(min_val, white_left+black_right)

print(min_val)

Submission status: Runtime Error

Solution code:
a = int(input())
b = list(input())
c = 0
for i in range(1,a):
  if b[i] == "#" and b[i+1] == ".":
    c += 1
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=[i for i in input()]
stp=0
for i in range(N-1,-1,-1):
    if S[i]=='.':
        flg=i
        break
    else:
        if i==0:
            stp=1
            flg=0
for i in range(N):
    if S[i]=='#':
        flg2=i
        break
    else:
        if i==N-1:
            stp=1
            flg2=0
for i in range(N):
    if S[i]=='.':
        flg3=i
        break

ans1=S[:flg].count('#')
ans2=S[flg2:].count('.')
ans3=S[flg3:].count('.')
ans=min(ans1,ans2,ans3)
if stp==1:
    ans=0
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
tmp=0
for i in range(n):
  lf s[i]==".":
    tmp+=1
ans=tmp
for i in range(n):
  if s[i]==".":
    tmp-=1
  else:
    tmp+=1
  ans=min(ans,tmp)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
l=list()
if '#' in s:
  for i in range(n):
    if s[i]=='#':
      l.append(i)
  for i in range(len(l)-1):
    if l[i+1]-l[i]>=2:
      cnt=l[i+1]
  if (cnt-l[0]+1)//2>l.index(cnt)+1:
    print(l.index(cnt)+1)
  else:
    print(cnt-l[0]-l.index(cnt))
else:
  print(0)

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
writing = [int(input()) for _ in range(m)]
thread = ()

for i in range(m-1, -1, -1):
    if writing[i] in thread:
        continue
    else:
        thread += (writing[i],)
thread_set = set(thread)
for i in range(n):
    if i+1 in thread_set:
        continue
    else:    
        thread += (i+1,)

for i in range(n):
    print(thread[i])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
print(min(s[s.index("#"):].count("."),s[:-1].count("#")))

Submission status: Runtime Error

Solution code:
from itertools import*
n=int(input())
s=input()
t=[len(list(v)) for k,v in groupby(s)]
r=s.count("#")
l=0
ans=[r,s.count(".")]

if s[0]=="#":
    for i in range(0,len(t)//2+1,2):
        r-=t[i+1]
        l+=t[i]
        ans.append(r+l)
else:
    for i in range(1,len(t)//2+1,2):
        r-=t[i+1]
        l+=t[i]
        ans.append(r+l)
print(min(ans))

Submission status: Runtime Error

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


a=s.find('#');b=s.rfind('.')

if a<b:
    c=s[a:b+1].count('#');d=s[a:b+1].count('.')
    ans=min(c,d)
else:
    ans=0

l=[]
for i in range(n):
    if s[i]=='.':
        l.append(i)

y=s[l[0]+1:].count('.')
for i in range(len(l)):
    x=s[:l[i]].count('#')
    ans=min(ans,x+y)
    y-=1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
s_int=[0 if x=="." else 1 for x in s]

res=float("inf")
kouho=[[0]*i+[1]*(n-i) for i in range(n+1)]

for item in kouho:
  res=min(res,sum([abs(item[i]-s_int)for i in range(n)]))

print(res)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
cnt_b,cnt_w=0,0
switch=0
for i in range(n):
    if s[i]=='#':
        switch=1
        if s[i:] in '.'
            cnt_b+=1
    if switch==1 and s[i]=='.':
        cnt_w+=1
if s[n-1]=='#':
    cnt_b-=1
print(min(cnt_b,cnt_w))

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
count_b_l = 0
count_w_r = 0
for i in range(len(s)):
    if s[i] == '.':
        count_w_r += 1
result = []
for i in range(len(s)):
    if s[i] == '#':
        count_w_l += 1
    else:
        count_b_r -= 1
    result.append(count_b_l+count_w_r)
print(min(result))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

n = int(input())
S = input()
ans = 0
l = 0
while l < n and S[l] == '.':
    l += 1
for r in range(l, n-1):
    if S[r:r+2] == '#.':
        m = r
    if S[r:r+2] == '.#':
        ans += min(r-m, m-l)+1
        l = r+1
if S[-1] == '.':
    ans += min(r-m, m-l)+1
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
s=input()
i=0
for c in s:
  if c=='#':
    ans=s[i:].count('.')
    break
  i+=1
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
b=0
w=S.count(".")
ans=b+w
for s in S:
  if s=="#":
    b+=1
  else:
	w-=1
  ans=min(ans, b+w)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
S = input()
a = list(S)
ans = 0

for i in range(n-2,-1,-1):

    if a[i] == "#" and a[i+1] == ".":
        bns += 1
        a[i] = "."

print(ans)

Submission status: Runtime Error

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

W = [0] * N
W[-1] += S[-1] == "."
for i in range(N - 2, -1, -1):
    W[i] = W[i + 1] + (S[i] == ".")

B = [0] * N
B[0] += S[0] == "#"
for i in range(1, N):
    B[i] = B[i - 1] + (S[i] == "#")

T = [w + b for w, b in zip(W, B)]
print(min(*T, W[0], B[-1]))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

int main(){
    int n; std::string stones; std::cin >> n >> stones;
    int count = 0;
    for (size_t i = 1; i < n; i++) {
        if ((stones[i-1] == '#') && (stones[i] == '.')) {
            stones.insert(stones.begin() + i, '#');       //  [2] の位置に '-' を挿入
            stones.erase(stones.begin() + i+1);       //  3番目の要素（'2'）を削除
            count += 1;
        }
    }
    printf("%d\n", count);
    return 0;
}

Submission status: Runtime Error

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

if "." not in s or "#" not in s:
    print(0)
else:
    ans = len(s)

    s = s[s.find("#"):n-s[::-1].find(".")]
    cnt_b = [0 for i in range(len(s))]
    cnt = 0
    for i in range(len(s)):
        if s[i] == "#":
            cnt += 1
        cnt_b[i] = cnt
    ans = min(ans, len(s)-cnt_b[-1])
    for i in range(len(s)):
        ans = min(ans, cnt_b[i] + (len(s)-cnt_b[-1])-(i+1-cnt_b[i]))
    print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())
l = input()
s = 0 
r = 0
for i in l :
  if i == "#":
    t +=1
  if t >= 1 and i == ".":
    s+=1
    r+=t
    t = 0
  
print(min(s,t))

Submission status: Runtime Error

Solution code:

a = int(input())
l = input()
s = 0 
for i in l :
  if i == "#":
    t = 1
  if t and i == ".":
    s+=1
  
print(s)

Submission status: Runtime Error

Solution code:
a = int(input())
l = list(map(int,input().split()))
s = 0 
for i ,j in zip(l,l[1:]):
  if i + j == "#.":s+=1
print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=input()
s=input()
char_list = list(s)
i=0
while 1:
  if char_list[i] == '.':
    break
  i+=1

s=s[i:]
print(s.count('#'))

Submission status: Runtime Error

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

result = S.count('.')
r = result
def dfs(i):
    global result
    global r
    if i == N:
        return float('inf')
    if S[i] == '#':
        r += 1
    else:
        r -= 1
    result = min(result,r)
    return min(result,dfs(i+1))

print(dfs(0))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
a = [0] * N
b = [0] * N
counter = []

if S[0] == '#':
    a[0] = 1
if S[N-1] == '.':
    b[N-1] = 1

for i in range(N-1):
    if S[i+1] == '#':
        a[i+1] = a[i] + 1
    else:
        a[i+1] = a[i]
    if S[N-i-2] =='.':
        b[N-i-2] = b[N-i-1] + 1
    else:
        b[N-i-2] = b[N-i-1]
        
for i in range(N-1):
    counter.append(a[i] + b[i+1])

print(min(counter))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ib = s.find('#')
cw = s[ib:].count('.')
cb = s.count('#')
if ib == -1:
  print('0')
elif cw >= cb:
  if s[-1] == '#':
  	iw = s.rfind('.')
    print(cb - (n - 1 - iw))
  else:
  	print(cb)
else:
  print(cw)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ib = s.find('#')
cw = s[ib:].count('.')
cb = s.count('#')
if ib == -1:
  print('0')
elif cw >= cb:
  if s[-1] == '#'
  	iw = s.rfind('.')
    print(cb - (n - 1 - iw))
  else:
  	print(cb)
else:
  print(cw)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N=int(input())
S=input()
black=[0]*N
white=[0]*N
for i,s in enumerate(S):
        if s=='#':
                black[i]=1
        else:
                white[i]=1
ans=[]
for i in range(N+1):
        ans.append(black[i]+white[i])
print(min(ans))

Submission status: Runtime Error

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

num_of_white = 0
num_of_black = 0

for i in range(1, N):
  if S[idx] == '.':
    num_of_white += 1

result = num_of_white

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

print(result)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
 
count[0] = S.count('.')
for i in range(1, len(S)+1):
    count[i] = count[i-1] + (1 if S[i-1]=='#' else 0) - (1 if S[i-1]=='.' else 0)

print(min(count))

Submission status: Runtime Error

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

count[0] = S.count('.')
for i in range(1, len(S)+1):
    count[i] = count[i-1] + (1 if S[i-1]=='#' else 0) - (1 if S[i-1]=='.' else 0)

print(min(count))

Submission status: Runtime Error

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

count[0] = S.count('.')
for i in range(1, len(S)+1):
    count[i] = count[i-1] + (1 if S[i-1]=='#' else 0) - (1 if S[i-1]=='.' else 0)

print(min(count))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
count = []
for i in range(n):
    if i == 0:
        ss = s.replace(".","")
        count[i] = int(len(ss))
    if i == n-1:
        ss = s.replace("#","")
        count[i] = int(len(ss))
    else:
        s1 = s[0:i-1]
        ss1 = s1.replace("#","")
        s2 = s[i:n-1]
        ss2 = s2.replace(".","")
        count[i] = int(len(ss1)+len(ss2))
print(max(count))

Submission status: Runtime Error

Solution code:

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

min_num = n
white_num = s.count('.')
black_num = 0

if white_num == n or s.count('#') == n:
    print(0)
else:
    for i in range(n):
        if s[i] == '#':
            black_num += 1
        else:
            white_num -= 1
        if min_num >= black_num + white_num
            min_num = black_num + white_num
    print(min_num)

Submission status: Runtime Error

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