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:
num_w = s.count('.')
num_b = s.count('#')
left_top = s[0] 
right_top = s[n - 1]
change_num = 0

if num_w == n: # 全て白なら
    change_num = 0
elif num_b == n: # 全て黒なら 
    change_num = 0
else:
    if num_w < num_b: # この場合，左端から連続している白を除く全ての白の場所を黒にする
        first_w = s.find('.')
        first_b = s.find('#')
        if s[first_w:].count('.') > s[first_w:].count('#'):
            change_num = s[first_w:].count('#')
        else:
            change_num = s[first_b:].count('.')
    elif num_w >= num_b: #この場合，右端から連続している黒を除く全ての黒の場所を白にする
        first_b = s.find('#')
        last_w = s.rfind('.')
        if s[first_b:].count('#') > s[first_b:].count('.'):
            change_num = s[first_b:].count('.')
        else:
            change_num = s[:last_w].count('#')

print(change_num)

Submission status: Runtime Error

Solution code:
in_data = [input() for i in range(3)] 
 
n = int(in_data[0])
s = in_data[1]

num_w = s.count('.')
num_b = s.count('#')
left_top = s[0] 
right_top = s[n - 1]
change_num = 0

if num_w == n: # 全て白なら
    change_num = 0
elif num_b == n: # 全て黒なら 
    change_num = 0
else:
    if num_w < num_b: # この場合，左端を除く全ての白の場所を黒にする
        change_num = s[1:].count('.')
    elif num_w >= num_b: #この場合，右端を除く全ての黒の場所を白にする
        change_num = s[:-1].count('#')

print(change_num)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
x = 0
y = 0

for i in range(len(N)):
  if S[i] == ".":
    x += 1
  else:
    y += 1
    
if x == 0 and y == 0:
  print(0)
elif x > y:
  print(x)
else:
  print(y)

Submission status: Runtime Error

Solution code:
input()
s = input()
while s[-1] == '#':
  s = s[:-1]
print(min(s.count("."), s.count("#")))

Submission status: Runtime Error

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

def white2black():
  most_left_black = S.index('#')

  if most_left_black == len(S) - 1:
    return 0
  else:
    subS = S[most_left_black + 1:]
    num_to_replace = subS.count('.')
    return num_to_replace

def black2white():
  most_right_white = max([i for i, c in enumerate(S) if c == '.' ])
  subS = S[:most_right_white]
  num_to_replace = subS.count('#')
  return num_to_replace

  
if not '#' in S:
  print(0)
else:
  print(min(white2black() , black2white()))

Submission status: Runtime Error

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


def main():
    n = int(input())
    s = list(input())

    if len(set(s)) == 1:
        print(0)
    else:
        ans = 0
        i = 0

        while i < n - 1:
            if s[i] == '#' and s[i + 1] == '.':
                ans += 1

                if i + 2 < n:
                    if s[i + 2] == '#':
                        i += 2
                    elif s[i + 2] == '.':
                        i += 3
                else:
                    print(ans)
                    exit()
            else:
                i += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
S = [1 if i == "." else 0 for i in input()]
# 黒は#,白が.
# 黒は0,白は1
# 黒の右に白は許されない
# ある場所を境に左は全部白、右は全部黒にするから、それの逆の個数を数える
# ある境より右にある白の数
rw = sum(S)
# ある境より左にある黒の数
lb = 0
min_temp = [rw+lb]
for idx,s in enumerate(S):
    # 黒の場合
    if s==0:
        # rw pass
        lb *= 1
    # 白の場合
    elif s==1:
        rw += 1
        lb -= 1
    # 小さい方を残す
    min_temp = min([min_temp,rw+lb])
    if min_temp == 0:break
print(min_temp)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
N = [[0 for _ in range(len(S))] for _  in  range(2)]
B,W = 0,1
# 左から.W 右へ#B
for idx,s in enumerate(S):
  if s is "#":
    N[idx][B] = N[idx-1][B] + 1
    N[idx][W] = N[idx-1][W]
  else:
    N[idx][B] = N[idx-1][B]
    N[idx][W] = N[idx-1][W] + 1

print(int(min([N[i][B]+N[-1][W]-N[i][W] for i in range(len(S)-1)]+[N[-1][W],N[-1][B]]   )))

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
S=list(s)
m=0
l=[]

for i in range(1,n):
    m=0
    for j in range(0,n):
        if j<i:
            if S[j]=='#':
                m=m+1
        
        else:
            if S[j]=='.':
                m=m+1
    
    l.append(m)

l.sort()
print(l[0])

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
S=list(s)
m=0
l=[]

for i in range(1,n):
    m=0
    for j in range(0,n):
        if j<i
            if S[j]=='#':
                m=m+1
        
        else:
            if S[j]=='.':
                m=m+1
    
    l.append(m)

l.sort()
print(l[0])

Submission status: Runtime Error

Solution code:
input()

S = input()
flag  = False

ans1 = 0
for c in S:
    if c == '#':
        flag = True
    if not(flag):
        continue
    if c == '.':
        ans1 += 1
ans2 = 0
for c in reversed(S):
 if c == '.':
        flag = True
    if not(flag):
        continue
    if c == '#':
        ans2 += 1


print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
S=list(s)
m=0
l=[]

for i in range(1,n):
    m=0
    for j in range(0,i):
        if S[j]=='#':
            m=m+1
    
    for j in range(i,n):
        if S[j]=='.':
            m=m+1
    
    l.append(m)

l.sort()
print(l[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from functools import reduce
l = int(input())
src = list(map(lambda x: 1 if x=="." else 0, input()))
lb = 0
rw = sum(src)
a = rw
for i in range(l):
  if src[i]==0:
    lb+=1
  else:
    rw-=1
  a = min(ans, left_black + right_white)
  if ans==0:
    break
print(ans)

Submission status: Runtime Error

Solution code:
l = int(input())
ss = input()
dn = ss.count('.')
dc = 0
if l != dn:
    for i in range(l):
        dc = dc + 1 if ss[i] == '.' else dc
        if dn/2 < dc:
            bits = ''.join(list(map(lambda s: '0' if s == '.' else '1', ss)))
            sbits = (''.join('0' for _ in range(dc))).join('1' for _ in range(l-dc))
            c0 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
            sbits = ''.join('1' for _ in range(l))
            c1 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
            print(c0 if c0 < c1 else c1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
l = int(input())
ss = input()
bits = ''.join(list(map(lambda s: '0' if s == '.' else '1', ss)))
n = bits.find('1')+1
if 0 <= n:
    sbits = (''.join('0' for _ in range(n))).join('1' for _ in range(l-n))
    c0 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
    sbits = ''.join('1' for _ in range(l))
    c1 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
    print(c0 if c0 < c1 else c1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
l = int(input())
ss = input()
bits = ''.join(list(map(lambda s: '0' if s == '.' else '1', ss)))
n = bits.find('1')
if 0 <= n:
    sbits = (''.join('0' for _ in range(n))).join('1' for _ in range(l-n))
    c0 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
    sbits = ''.join('1' for _ in range(l))
    c1 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
    print(c0 if c0 < c1 else c1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
l = int(input())
ss = input()
bits = ''.join(list(map(lambda s: '0' if s == '.' else '1', ss)))
n0 = bits.find('0')
n1 = bits.find('1')
if 0 <= n1:
    sbits = (''.join('0' for _ in range(n1))).join('1' for _ in range(l-n1))
    c0 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
    sbits = (''.join('0' for _ in range(n0))).join('1' for _ in range(l-n0))
    c1 = bin(int(bits, 2) ^ int(sbits,2)).count('1')
    print(c0 if c0 < c1 else c1)
else:
    print(0)

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:
l = int(input())
ss = input()
bits = ''.join(list(map(lambda s: '0' if s == '.' else '1', ss)))
n = bits.find('1')
if 0 <= n:
    sbits = (''.join('0' for _ in range(n))).join('1' for _ in range(l-n))
    print(bin(int(bits, 2) ^ int(sbits,2)).count('1'))
else:
    print(0)

Submission status: Runtime Error

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

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

for j in range(i+1, N):
    if S[j] == ".":
        count += 1

print(count)

Submission status: Runtime Error

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

a,b = 0,0
for i in s:
    if i == '.':
        a += 1 #白の個数
    else:
        b += 1 #黒の個数

min_c = 10**10
if s[0] == '.':
    counta, countb = 0, 0
    for k, i in enumerate(s):
        if s[k] == '.':
            counta += 1
        if s[k] == '#':
            countb += 1
            c = (a - counta) + (countb - 1)
        if min_c > c:
            min_c = c
        
print(min(a,b, min_c))

Submission status: Runtime Error

Solution code:
N=int(input())
S=input().split()
ans_1=0
ans_2=0

for i in range(0,N-1):
    for m in range(0,i)
        if S[m]=".":
            ans_1+=1
        else:
            ans_2+=1
    for k in range(i,N-1):
        if S[k]="#":
            ans_1+=1
        else:
            ans_2+=1

print(min(ans_1,ans_2))

Submission status: Runtime Error

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)

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

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
s_list = list(s)
count1 = 0
count2 = 0

for i in range(n):
    if(s_list[i] == '#'):
        for j in range(0,n-1):
            #print(s_list[j+i])
            #print(j)
            if(s_list[j+i+1] == '.'):
                #print("count")
                count1 = count1 + 1
        break


for i in range(n):
    if(s_list[i] == '#'):
        count2 = count2 + 1


if(count1 < count2):
    print(count1)
else:
    print(count2)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
i=0
m=N-1
cnt_1=0
cnt_2=0

while S[i]==".":
    i+=1
while S[m]=="#":
    m-=1

for x in range(i,m):
    if S[x]==".":
        S[x]="#"
        cnt_1+=1
for x in range(i,m):
    if S[x]=="#":
        S[x]="."
        cnt_2+=1

if cnt_1>=cnt_2:
    print(cnt_2)
else:
    print(cnt_1)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    S = input()
    for i in range(N):
        if S[i] == '.':
            pass
        else:
            first_black = i
            break
    sum = 0
    for i in range(first_black+1, N):
        if S[i] == '.':
            sum += 1
        else:
            pass
    print(sum)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

count=S.count(".")
first=S.index("#")

print(count-first) if "#" in S else print(N)

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

data = []

def split_data(data, i):
    return (S[:i+1].count('#'),S[i+1:].count('.'))

# .......####### という形を目指す

#累積和を計算
sum_black = [0]
sum_white = [0]
for n in range(0,N+1):
    if S[n] == '#': #black
        sum_black.append(sum_black[n] + 1)
        sum_white.append(sum_white[n] + 0)
    else:
        sum_black.append(sum_black[n] + 0)
        sum_white.append(sum_white[n] + 1)

num_min = N
for n in range(0,N):
    num = sum_black[n] + (sum_white[n] - sum_white[-1]) 
    if num < num_min:
        num_min = num

print(num_min)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == '.':
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
A = cw[N]
for i in range(N):
    A = min(A, cb[i] + cw[N - 1] - cw[i])
print(A)

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(len(S) - 1):
    if S[i] == '#' and S[i+1] == '.':
        ans += 1
if S.count('.') > S.count('#'):
    ans_c = S.count('#')
else:
    ans_c = S.count('.')
if ans < ans_c:
    print(ans)
else:
    print(ans_c)

Submission status: Runtime Error

Solution code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/*Atcoder用
 * 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String get = br.readLine();
		char[] s = get.toCharArray();
		for(char c:s)System.out.println(c);

		List<Integer> ls = new ArrayList<Integer>();
		String[] tmp = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			ls.add(Integer.parseInt(tmp[n]));
		}
 */

public class Main {

	public static void main(String[] args) throws IOException {
 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		int N = Integer.parseInt(num);
		String get = br.readLine();
		char[] S = get.toCharArray();

		List<Integer> whiteNum = new ArrayList<Integer>();
		List<Integer> blackNum = new ArrayList<Integer>();

		int count = 0;
		for(int i = 0;i<S.length;i++){
			if(S[i] == '.')count++;
			whiteNum.add(count);

		}
		count = 0;
		for(int i = 0;i<S.length;i++){
			if(S[i] == '#')count++;
			blackNum.add(count);
		}

		int min = (int) Math.pow(10,10);
		for(int j = 0;j<S.length;j++){
			count = blackNum.get(j) + (whiteNum.get(S.length-1) - whiteNum.get(j));
			min = Math.min(min, count);
		}

		System.out.println(min);

	}

}

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
n_sharp = S.count("#")
n_period = S.count(".")
temp = [[], []]
k = 0
for i in range(N - 1):
    if S[i] == "#" and S[i + 1] == ".":
        temp[0].append(S[:i + 1].count("#"))
        # print(S[:i + 1], S[i + 1:])
        temp[1].append(S[i + 1:].count("."))
        k += 1
        if k == 1:
            ans = min(temp[0], temp[1])[0]
            # print((ans))
        elif k > 1:
            ans += min(abs(temp[0][k-1] - temp[0][k - 2]), abs(temp[1][k-1] - temp[1][k - 2]))

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
n_sharp = S.count("#")
n_period = S.count(".")
temp = [[], []]

for i in range(N - 1):
    if S[i] == "#" and S[i + 1] == ".":
        temp[0].append(S[:i + 1].count("#"))
        temp[1].append(S[i + 1:].count("."))
_ = len(temp[0])
ans = min(temp[0])
for i in range(_ -1):
    ans += min(abs(temp[0][i + 1] - temp[0][i]), abs(temp[1][i + 1] - temp[1][i]))
print(ans)

Submission status: Runtime Error

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
    dbg(numSB,numSW,numSR)
    if numSB <= numSW and numSB <= numSR:
        return numSB
    elif numSW <= numSB and numSW <= numSR:
        return numSW
    else:
        return numSR + count2(numSB+b,numSW+w)
    # if numSB <= numSW :
    #     return numSB
    # else:
    #     return numSW
    
    

# def count(_S,_numSW,_numSB):
#     _S = _S.lstrip('.').rstrip('#')
#     if len(_S) == 0 :
#         return 0
#     numSW = _S.count('.')
#     numSB = _S.count('#')
#     SR = _S.lstrip('#').rstrip('.')
#     numSR = len(_S) - len(SR)
#     if numSW <= numSB and numSW <= numSR:
#         return numSW
#     elif numSB <= numSW and numSB <= numSR:
#         return numSB
#     else:
#         return numSR + count(SR)


numSB = 0
numSW = 0
for i,v in enumerate(sint):
    if i % 2 == 1:
        numSB = numSB + v
    else:
        numSW = numSW + v
#print(sint)
#print(sint,numSB,numSW,count2(numSB,numSW))
numSR = count2(numSB,numSW)
dbg('numSW:',numSW)
dbg('numSB',numSB)
dbg('numSR',numSR)
print(min(numSB,numSW,numSR))
'''
22
#####.....####..###...####....#.#.#
'''
# #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: Runtime Error

Solution code:
N = int(input())
S = input()
cnt = 0
i = 0
while S[i] == '.':
    i += 1

j = i

for i in range(N - j):
    if S[i] == '.':
        cnt += 1
        
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
min = N
if S.find('#') == -1 or S.find('.') == -1:
    min = 0
else:
    for i in range(S.find('#'),N - 1):
        if S[i] == '.' and S[i+1] == '#':
            left = S.count('#',0,i)
            right = S.count('.',i+1)
        elif S[i] == '#' and S[i+1] =='.':
            left = S.count('#',0,i)
            right = S.count('.',i)
        if left + right < min:
            min = left + right
print(min)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
min = N
if S.find('#') == -1 or S.find('.') == -1:
    min = 0
else:
    for i in range(S.find('#'),S.rfind('#')+1):
        if S[i] == '.' and S[i+1] == '#':
            left = S.count('#',0,i)
            right = S.count('.',i+1)
        elif S[i] == '#' and S[i+1] =='.':
            left = S.count('#',0,i)
            right = S.count('.',i)
        if left + right < min:
            min = left + right
print(min)

Submission status: Runtime Error

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()
    
    #この状態で偶数番号は黒、奇数番号は白(ゼロスタート)
    # numSB = 0
    # numSW = 0
    # for i,v in enumerate(sint):
        
    #     if i % 2 == 0:
    #         numSB = numSB + v
    #     else:
    #         numSW = numSW + v
    if len(sint) < 2:
        return 0
    b = sint.pop(0)
    w = sint.pop()
    
    numSR =  b + w
    dbg(numSB,numSW,numSR)
    if numSB <= numSW and numSB <= numSR:
        return numSB
    elif numSW <= numSB and numSW <= numSR:
        return numSW
    else:
        return numSR + count2(numSB-b,numSW-w)
    # if numSB <= numSW :
    #     return numSB
    # else:
    #     return numSW
    
    

# def count(_S,_numSW,_numSB):
#     _S = _S.lstrip('.').rstrip('#')
#     if len(_S) == 0 :
#         return 0
#     numSW = _S.count('.')
#     numSB = _S.count('#')
#     SR = _S.lstrip('#').rstrip('.')
#     numSR = len(_S) - len(SR)
#     if numSW <= numSB and numSW <= numSR:
#         return numSW
#     elif numSB <= numSW and numSB <= numSR:
#         return numSB
#     else:
#         return numSR + count(SR)


numSB = 0
numSW = 0
for i,v in enumerate(sint):
    if i % 2 == 1:
        numSB = numSB + v
    else:
        numSW = numSW + v
#print(sint)
#print(sint,numSB,numSW,count2(numSB,numSW))
print(min(numSB,numSW,count2(numSB,numSW)))
'''
22
#####.....####..###...
'''
# #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: Runtime Error

Solution code:
N = int(input())
S = input()
sint = [0]
si = 0
prev = S[0]

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

def count2(numSB,numSW):
    if len(sint) <= 2:
        return 0
    sint.pop(0)
    sint.pop()
    
    #この状態で偶数番号は黒、奇数番号は白(ゼロスタート)
    # numSB = 0
    # numSW = 0
    # for i,v in enumerate(sint):
        
    #     if i % 2 == 0:
    #         numSB = numSB + v
    #     else:
    #         numSW = numSW + v
    if len(sint) <= 2:
        return 0
    b = sint.pop(0)
    w = sint.pop()
    
    numSR =  b + w
    #print(numSB,numSW,numSR)
    if numSB <= numSW and numSB <= numSR:
        return numSB
    elif numSW <= numSB and numSW <= numSR:
        return numSW
    else:
        return numSR + count2(numSB-b,numSW-w)
    # if numSB <= numSW :
    #     return numSB
    # else:
    #     return numSW
    
    

def count(_S,_numSW,_numSB):
    _S = _S.lstrip('.').rstrip('#')
    if len(_S) == 0 :
        return 0
    numSW = _S.count('.')
    numSB = _S.count('#')
    SR = _S.lstrip('#').rstrip('.')
    numSR = len(_S) - len(SR)
    if numSW <= numSB and numSW <= numSR:
        return numSW
    elif numSB <= numSW and numSB <= numSR:
        return numSB
    else:
        return numSR + count(SR)


numSB = 0
numSW = 0
for i,v in enumerate(sint):
    if i % 2 == 1:
        numSB = numSB + v
    else:
        numSW = numSW + v
#print(sint,numSB,numSW)
print(min(numSB,numSW,count2(numSB,numSW)))
'''
22
#####.....####..###...
'''
# #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: Runtime Error

Solution code:
n=input()
s=input()
if n<=100000:
  print(0)
else:
  t=0
  while t<=2:
    t=t

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
sint = [0]
si = 0
prev = S[0]

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

def count2(numSB,numSW):
    if len(sint) <= 4:
        return 0
    sint.pop(0)
    sint.pop()
    
    #この状態で偶数番号は黒、奇数番号は白(ゼロスタート)
    # numSB = 0
    # numSW = 0
    # for i,v in enumerate(sint):
        
    #     if i % 2 == 0:
    #         numSB = numSB + v
    #     else:
    #         numSW = numSW + v
    b = sint.pop(0)
    w = sint.pop()
    
    numSR =  b + w
    #print(numSB,numSW,numSR)
    if numSB <= numSW and numSB <= numSR:
        return numSB
    elif numSW <= numSB and numSW <= numSR:
        return numSW
    else:
        return numSR + count2(numSB-b,numSW-w)
    # if numSB <= numSW :
    #     return numSB
    # else:
    #     return numSW
    
    

def count(_S,_numSW,_numSB):
    _S = _S.lstrip('.').rstrip('#')
    if len(_S) == 0 :
        return 0
    numSW = _S.count('.')
    numSB = _S.count('#')
    SR = _S.lstrip('#').rstrip('.')
    numSR = len(_S) - len(SR)
    if numSW <= numSB and numSW <= numSR:
        return numSW
    elif numSB <= numSW and numSB <= numSR:
        return numSB
    else:
        return numSR + count(SR)


numSB = 0
numSW = 0
for i,v in enumerate(sint):
    if i % 2 == 1:
        numSB = numSB + v
    else:
        numSW = numSW + v
#print(sint,numSB,numSW)
print(min(numSB,numSW,count2(numSB,numSW)))
'''
22
#####.....####..###...
'''
# #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: Runtime Error

Solution code:
N = int(input())
S = input()
sint = [0]
si = 0
prev = S[0]

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

def count2(numSB,numSW):
    if len(sint) <= 2:
        return 0
    sint.pop(0)
    sint.pop()
    
    #この状態で偶数番号は黒、奇数番号は白(ゼロスタート)
    # numSB = 0
    # numSW = 0
    # for i,v in enumerate(sint):
        
    #     if i % 2 == 0:
    #         numSB = numSB + v
    #     else:
    #         numSW = numSW + v
    b = sint.pop(0)
    w = sint.pop()
    
    numSR =  b + w
    #print(numSB,numSW,numSR)
    if numSB <= numSW and numSB <= numSR:
        return numSB
    elif numSW <= numSB and numSW <= numSR:
        return numSW
    else:
        return numSR + count2(numSB-b,numSW-w)
    # if numSB <= numSW :
    #     return numSB
    # else:
    #     return numSW
    
    

def count(_S,_numSW,_numSB):
    _S = _S.lstrip('.').rstrip('#')
    if len(_S) == 0 :
        return 0
    numSW = _S.count('.')
    numSB = _S.count('#')
    SR = _S.lstrip('#').rstrip('.')
    numSR = len(_S) - len(SR)
    if numSW <= numSB and numSW <= numSR:
        return numSW
    elif numSB <= numSW and numSB <= numSR:
        return numSB
    else:
        return numSR + count(SR)


numSB = 0
numSW = 0
for i,v in enumerate(sint):
    if i % 2 == 1:
        numSB = numSB + v
    else:
        numSW = numSW + v
#print(sint,numSB,numSW)
print(min(numSB,numSW,count2(numSB,numSW)))
'''
22
#####.....####..###...
'''
# #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))