Problem:


Score : 300 points

Problem Statement

There are N stones arranged in a row. Every stone is painted white or black.
A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.

Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.
Find the minimum number of stones that needs to be recolored.

Constraints

1 \leq N \leq 2\times 10^5

S is a string of length N consisting of . and #.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the minimum number of stones that needs to be recolored.

Sample Input 1

3
#.#

Sample Output 1

1

It is enough to change the color of the first stone to white.

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
a = 0
b = 0
for i in range(n):
  if s[i] == ".":
    a += 1
  else:
    break
for i in range(n):
  if s[-i-1] =="#":
    b += 1
  else:
    break
sb = s.count("#")
sw = s.count(".")
if sb-b>sw-a:
  print(sw-a)
else:
  print(sb-b)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = [str(i) for i in input()]

    next_black_num = 0
    pre_stone = "."

    for s in S:
        if pre_stone == "#" and s == ".":
            next_black_num += 1
        pre_stone = s

    print(min([next_black_num, N - next_black_num]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flug = False
cnt1 = 0
for i,n in enumerate(S):
    if S[i]=='#':
        flug=True
    else:
        if flug and S[i]=='.':
            cnt1+=1
        else:
            flug=False

flug = False
cnt2 = 0
S_rev = S[::-1]
for i,n in enumerate(S_rev):
    if S_rev[i]=='.':
        flug=True
    else:
        if flug and S_rev[i]=='#':
            cnt2+=1
        else:
            flug=False
    
print(min(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
SIRO = '.'
KURO = '#'
N = int(input())
S = input()
ans = 0
kCnt = S.count(KURO)
sCnt = S.count(SIRO)
if sCnt >= kCnt:
    for i in range(0, N - 1):
        if S[i] == KURO:
            if S[i + 1] == SIRO:
                ans += 1
else:
    for i in range(1, N):
        if S[i] == SIRO:
            if S[i - 1] == KURO:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
change_list = []
change_list.append(0)
result1 = 0
result2 = 0
for i in range(N-1):
	if S[i] !=S[i+1]:
		change_list.append(i+1)
change_list.append(N)
if S[0] == '.':
	for i in range(2,len(change_list)):
		if i % 2==0:
			result1+=change_list[i]-change_list[i-1]
		else:
			result2+=change_list[i]-change_list[i-1]
	print(min(result1,result2))
else:
	start = change_list[1]-change_list.pop(0)
	for i in range(2,len(change_list)):
		if i % 2==0:
			result1+=change_list[i]-change_list[i-1]
		else:
			result2+=change_list[i]-change_list[i-1]
	print(min(result1+start,result2+start,S.count('.')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
first_B = S.find('#')
if first_B == -1:
    answer = 0
else:
    S = S[first_B:]
#    print(S)
    n_W = S.count('.')
    n_B = S.count('#')
    if n_W > n_B:
        answer = n_B
    else:
        answer = n_W
print (answer)

Submission status: Wrong Answer

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

cnt = 0
count_flag = False
for i in range(0, n-1):
  if s[i] == '#' and s[i+1] =='.':
    count_flag = True
    cnt += 1
  elif s[i+1] == '.' and count_flag:
    cnt += 1
  else:
    count_flag = False

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline())
s = sys.stdin.readline()

bcnt = 0
wcnt = 0
bst = 10 ** 13
lastlen = 0

for i in range(n):
    tmp = s[i:i + 1]
    if tmp == "#":
        bcnt += 1
        if bst > i:
            bst = i
        lastlen += 1
    else:
        if i > bst:
            wcnt += 1
        lastlen = 0

print(min(wcnt, bcnt-lastlen))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
k = 0
s = 0
ans0 = 0
ans1 = 0

for i in range(N):
    if S[i] == "#":
        k = i
        break

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

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

for i in range(s-1,-1,-1):
    if S[i] == "#":
        ans1 += 1

print(min(ans0,ans1))

Submission status: Wrong Answer

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

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

else:
    x = S[S.find("#"):].count(".")
    y = S[:S.rfind(".")].count("#")
    print(min(x,y))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())

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

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

que = deque([])

flag = False # White
tmp = 0

for s in S:
    if flag:
        if s == "#":
            tmp += 1
        else:
            que.append(tmp)
            tmp = 1
            flag = not flag
    else:
        if s == ".":
            tmp += 1
        else:
            que.append(tmp)
            tmp = 1
            flag = not flag

que.append(tmp)

if not flag:
    que.append(0)


# dont care
que.popleft()
que.pop()

if len(que) == 0:
    print(0)
    exit()

fe = que.popleft()
be = que.pop()
result = 0

while 1:
    if fe > be:
        result += be
        if len(que) == 0:
            break
        else:
            que.pop()
            be = que.pop()
    else:
        result += fe
        if len(que) == 0:
            break
        else:
            que.popleft()
            fe = que.popleft()


print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
for i in range(N):
    if S[i]=='.':
        break
ans = i + min(S[i+1:].count('#'), S[i+1:].count('.'))
if S[-1]=='#' and len(S[i+1:])!=1:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
s=[s[i] for i in range(len(s))]
hit1=0
count1=0
for i in s:
    if i=="#":
        hit1 = 1
    if i==".":
        count1=count1+hit1
        
count2=0
hit2=0
for i in range(len(s)):
    if s[-1-i]==".":
        hit2 = 1
    if s[-1-i]=="#":
        count2=count2+hit2
        
print(min(count1,count2))

Submission status: Wrong Answer

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

#左からleft_count番目が黒い石

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

right_count = 1
for i in range(n):
    if s[-(i + 1)] == ".":
        break
    right_count = right_count + 1

print(left_count, right_count)

w_count = 0
for i in range(n - left_count):
    if s[i + left_count] == ".":
        w_count = w_count + 1

b_count = 0
for i in range(n - right_count):
    if s[i] == "#":
        b_count = b_count + 1

print(min(w_count, b_count))

Submission status: Wrong Answer

Solution code:
def c_stones(N, S):
    import itertools
    s = [(k, len(list(v))) for k, v in itertools.groupby(S)]
    if s[0][0] == '.':
        del s[0]
    if len(s) > 0 and s[-1][0] == '#':
        del s[-1]
    ans = 0
    for i in range(0, len(s), 2):
        ans += min(s[i][1], s[i + 1][1])
    return ans

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

Submission status: Wrong Answer

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

finded_black = False
answer1 = 0

for c in s:
    if finded_black:
        if c == '#':
            continue
        else:
            answer1 += 1

    if not finded_black:
        if c == '.':
            continue
        else:
            finded_black = True

finded_white = False
answer2 = 0

tmp = list(reversed(s))

for c in tmp:
    if finded_white:
        if c == '.':
            continue
        else:
            answer2 += 1

    if not finded_white:
        if c == '#':
            continue
        else:
            finded_white = True

print(min(answer1, answer2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
#" . #
#  b=black#
#  w=white.
f=[0,1][s[0]=="#"]
g=[0,1][s[0]=="."]
b=[f]
w=[0]
#print(b,w)
for i in s:
#    print(w)
    if f==1 and i=="#":
        b[-1]+=1
    elif f==1 and i==".":
        f=0
        if w[-1]!=0: w.append(1)
        else: w[-1]=1
    elif b[-1]!=0 and f==0 and i==".":
        w[-1]+=1
    elif f==0 and i=="#":
        f=1
        if b[-1]!=0: b.append(1)
        else: b[-1]=1
x=sum(b)
y=sum(w)
if s[-1]=="#": x-=b[-1]

ans=min(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
a = s.find('#') #左から黒
b = s.rfind('.') #右から白

ans = min([s[a:n].count('.'),s[0:b].count('#')])
print(ans)

Submission status: Wrong Answer

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

b = 0
w = 0
for s in S:
  if s == "#":
    b += 1
  else:
    w+=1
  
  
print(min(b,w))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if s.count('.') == len(s):
    print(0)
else:
    for i, wb in enumerate(s):
        if wb == '#':
            break
        else:
            s = s[i+1:]
    
    ans = min(s.count('.'), s.count('#'))
    print(ans)

Submission status: Wrong Answer

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

CT=0
for j in range(len(S)):
    if S[j] == ".":
        CT+=1

#NG: #.
#OK: .#
CH=0
A=CT+CH
for i in range(len(S)):
    if S[i] == ".":
        CT-=1
    if S[i] == "#":
        CH+=1
        break

    A=min(CT+CH, A)

print(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S == '.' * N:
  print(0)
else:
  first = 0
  for i in range(1,N+1):
    if S[i-1] == '#':
      first = i
      break
  out1 = 0
  for i in range(first+1,N+1):
    if S[i-1] =='.':
      out1 += 1
  second = 0
  for i in range(1,N+1):
    if S[N-i] == '.':
      second = i
      break
  out2 = 0
  for i in range(second+1,N+1):
    if S[N-i] =='#':
      out2 += 1
  print(min(out1,out2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if S.count('#')==N or S.count('.')==N:
    print(0)
elif S[0]=='#':
    print(min(S.count('#'),S.count('.')))
else:
    renzoku=1
    for i in range(1,N):
        if S[i]=='.':
            renzoku+=1
        else:
            break
    S=S[renzoku:]
    print(min(S.count('#'),S.count('.')))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
memo = 0
count = 0
if "#" in S:
    for i in range(N):
        if S[i] == "#":
            memo = i
            #S_right = S[i+1:]
            break
    for j in range(i,N):
        if S[j] == ".":
            S_right = S[memo:]
            count = S_right.count(".")
            break

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	S = input()
	S = S[:-1]

	ans = 0
	flg = False
	for i in S:
		if i == "#":
			flg = True
			continue
		if flg == True and i == ".":
			ans += 1

	print(ans)

	

	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
stemp=input()
s=[ i for i in stemp]

s2=copy.copy(s)
ans=0
ans2=0
for i in range(n):
    #print(i)
    if 1<=i and i<=n-1:
        if s[i]==".":
            ans+=1
    if i<=n-2:
        if s2[i]=="#":
            ans2+=1

#print(s)
#print(s2)
#print(ans,ans2)
print(min(ans,ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input()
s = input()
i = s.find('#')
if i < 0:
    print(0)
else:
    print(min(s[i+1:].count('.'),s.count('#')))

Submission status: Wrong Answer

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

cnt = 0
for i in range(1,n):
    if (l[i-1] == "#")&(l[i-1] != l[i]):
        l[i] = "#"
        cnt += 1
    else:
        continue
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
_ = int(input())
s = list(input()) + [' ']
try:
    sl = s[s.index('#'):]
    if sl.count('#') > sl.count('.'):
        print(sl.count('.'))
    else:
        print(sl.count('#'))
except:
    print(0)

Submission status: Wrong Answer

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

si=[]
k=[]
count = 0
flag = 0
for i in range(0,n):
    if flag == 0:
        if s[i] == '.':
            count += 1
        else:
            si.append(count)
            count = 1
            flag = 1
    else:
        if s[i] == '#':
            count += 1
        else:
            k.append(count)
            count = 1
            flag = 0

if len(si)>0:
    sa=si[0]
else:
    sa=0
if len(k)>0:
    ka=k[-1]
else: ka = 0

smax = sum(si) - sa

kmax = sum(k) - ka

ans = min(smax,kmax)
print(ans)

Submission status: Wrong Answer

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

count = 0

for i in range(1,n):
    if s[-i] == '#':
        count += 1

s = s[:n-count]
sharp_num = s.count('#')
dot_num = s.count('.')

print(min(sharp_num,dot_num))

Submission status: Wrong Answer

Solution code:
N=input()
S=list(map(str,input()))

index_num = [n for n,v in enumerate(S) if v =='#']
count = 0
for i in index_num:
    if i!=len(S)-1 and S[i+1]=='.':
        count += 1
print(count)

Submission status: Wrong Answer

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

print(min(a,b))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop


def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))


def runLength(in_str):
    kukan = 1
    start = 0
    ret = []
    for i in range(1,len(in_str)):
        if in_str[i-1]!=in_str[i]:
            ret.append([in_str[i-1],kukan,start])
            start = i
            kukan=0
        kukan+=1
    ret.append([in_str[-1],kukan,start])
    return ret

N = int_raw()
S= input()

dp = {}

def rec(ss):
    return 0

def main():
    ans =0
    numB = 0
    leftMostW = -1
    
    for i in range(len(S)-1,-1,-1):
        if S[i]==".":
            leftMostW = i
            break
    if leftMostW ==-1:
        return 0
    leftsW = 0
    for i in range(leftMostW):
        if S[i] == "#":
            if leftsW ==0:
                leftsW = i
            numB+=1

    return min(numB,leftMostW+1-numB-leftsW)



print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
f = 0
count = 0
for i in range(n):
    if s[i] == "#":
        f = i+1
        #print(f)
        break
    else:
        f = -1
if f != -1:
    for i in range(f,n):
        if s[i] == ".":
            count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        break
#print(dot)
#print(sha)
print(dot+sha)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

ans=0

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
 
def a(str) :
	for i in range(n) :
		if str[i] == "#" : return i
	return -1
index = a(s)
ansW = 0
ansB = 0
if index != -1 :
	for i in range(index, n) :
		if s[i] == "." : ansW +=1
		else : ansB += 1
print (min(ansW,ansB))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cmp1,cmp2 = 0,0

if s.count('.') == n:
    print('0')
else:
    cmp1 = s[s.index('#'):].count('.')
    reverse_s = s[::-1]
    cmp2 = reverse_s[reverse_s.index('#')+1:].count('#')
    print(min(cmp1,cmp2))

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
scount=0
ccount=0
ll=list()
for i in b:
        ll.append(i)
if "#" in ll:
        x=ll.index("#")
        y=ll.count(".")
        z=y-x
        ccount=z
print(ccount)

Submission status: Wrong Answer

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

cnt1 = 0; # #. の数
for i in range(N):
    if str(S[i]) == "." and str(S[i-1])=="#":
        cnt1 += 1

print(cnt1)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())                                                                                                                                           
S = list(raw_input())                                                                                                                                          
                                                                                                                                                               
c = 0                                                                                                                                                          
for i in range(N):                                                                                                                                             
      if S[N-1-i] == "#":                                                                                                                                      
            c += 1                                                                                                                                             
      else:                                                                                                                                                    
            break                                                                                                                                              
if c > 0:                                                                                                                                                      
      S = S[:-c]                                                                                                                                               
                                                                                                                                                               
cc = 0                                                                                                                                                         
                                                                                                                                                               
for j in range(N-c):                                                                                                                                           
      if S[j] == ".":                                                                                                                                          
            cc += 1                
if N-cc > 0:
      print(min(cc, N-c-cc))
else:
      print("0")

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
tmp = S.count('#.')
counter = 0
for i in range(tmp):
    count = S.find('#.') + 1
    S_list = list(S)
    while True:
        if count < len(S):
            if S_list[count] == '.':
                counter += 1
                S_list[count] = '#'
                count+= 1
            else:
                break
        else:
            break
    S = ''.join(S_list)
print(counter)

Submission status: Wrong Answer

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

'''考え方
1.白・黒それぞれの一番左端の位置を確認する
2.黒の右に白い石が存在するか否かを判断
3.変更するべき石の数が、白・黒どちらの方が多いか判断
'''

first_white = S.find('.')
first_black = S.find('#')
last_white = S.rfind('.')
last_black = S.rfind('#')

# blackのラストブロックのサイズを求めておく

cnt = 1
for s in reversed(S[:last_black]):
  if s == '#':
    cnt += 1
  else:
    break


out = 0


# 1.どちらか一色のみ 
if first_black == -1 or first_white == -1:
  out = 0

# 2.黒い石よりも右側に白色の石が存在する場合
elif S[first_black:].find('.') > -1:
  # 2-1.一番右のブロックが白色
  if last_white > last_black:
    cnt_white = S[first_black:].count('.')
    cnt_black = S[first_black:].count('#')
  # 2-2.一番右のブロックが黒色
  else:
    cnt_white = S[first_black:].count('.')
    cnt_black = S[first_black:].count('#') - cnt

  out = min(cnt_white,cnt_black)

# 3.左に白、右に黒、と完全に別れる場合
elif last_white < first_black:
  out = 0

print(out)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = raw_input()
S = raw_input()
 
flag = 0
cnt = 0
for s in S:
    if s == '#':
        flag = 1
    elif s == '.' and flag ==1:
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
right = []
left = []
cnt = [0 for x in range(N)]
for x,y,z in zip(S[:N:],S[1::],range(N)):
    if x == '#' and y == '.':
        cnt[z] = 1
        right.append(z)
    elif x == '.' and y == '#':
        cnt[z] = -1
        left.append(z)
left.append(N-1)
try:
    if right[0]>left[0]:
        left.pop(0)
except:
    pass
for x,y in zip(right,left):
    ans += y-x
print(ans)

Submission status: Wrong Answer

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

ans = 0
answ = 0
ansb = 1
c = 0

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

if c == 0:
    print(0)

else:

    for i in range(n):

        if s[i] == "#":

            for j in range(n-i-1):
                
                if s[i+1+j] == ".":
                    answ += 1
                else:
                    ansb += 1

            if ansb <= answ:
                ans = ansb
            else:
                ans = answ   
                
            print(ans)
            break

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    S = input()
    ps = ''
    ans = 0
    f = False
    for s in S:
        if s == '.' and ps == '#':
            ans += 1
            f = True
        elif s == '.' and ps == '.' and f is True:
            ans += 1
        elif s == '#' and ps == '.' and f is True:
            f = False

        ps = s
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
counter_=0
counterk=0
for i in range(N):
  if(S[i]=="*"):
    counterk+=1
  else:
    counter_+=1
if(counterk>=counter_):
  print(counter_)
else:
  print(counterk)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
cnt = 0
for s in S:
    if s =='#':
        cnt += 1

if cnt:
    print(min(N-cnt,cnt))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

l = raw_input().split()
N = int(l[0])
l = raw_input().split()
S1 = list(l[0])

S = []
found = False
for s in S1:
    if s == '#':
        found = True
    if not found:
        continue
    S.append(s)

num_black = 0
num_white = 0

temp_black = 0
for s in S:
    if s == '#':
        temp_black += 1
    else:
        num_white += 1
        num_black += temp_black
        temp_black = 0

print(min(num_black, num_white))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input())
b=a.copy()

sum=0
sum2=0

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

Submission status: Wrong Answer

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

zeros = ["." for i in range(N)]
ones = ["#" for i in range(N)]
lastone = ["." for i in range(N - 1)]
lastone.append("#")
firstzero = ["#" for i in range(N - 1)]
firstzero.insert(0, ".")
z = 0
o = 0
l = 0
f = 0

for i in range(N):
    if S[i] != zeros[i]:
        z += 1

for i in range(N):
    if S[i] != ones[i]:
        o += 1

for i in range(N):
    if S[i] != lastone[i]:
        l += 1

for i in range(N):
    if S[i] != firstzero[i]:
        f += 1

print(min([z, o, l, f]))

Submission status: Wrong Answer

Solution code:
import sys
import math
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N = ni()
S = ns()

#最初のBが出てくるまでを数える
fastB = False
fastW = False
secondB=False
w0,w1,b0,b1 = 0,0,0,0

for s in S:
    if(s=="."):
        #print("w")
        if(fastB and fastW):
            secondB=True
            w1+=1
        else:
            fastW=True
            w0+=1
    elif(s=="#"):
        #print("b")
        if(fastB and fastW and secondB):
            b1+=1
        else:
            fastB=True
            fastW=True
            b0+=1

#print(b0+b1,w0+w1,w1)
#print(b0,b1,w0,w1)

print(min(b0+b1,w0+w1,w1))

Submission status: Wrong Answer

Solution code:
def cutw(s,n):
    t = 0
    for i in range(n):
        if s[i] == '#':
            break
        else:
            t += 1
    s = s[t:]
    n = len(s)
    return s,n

def cutb(s,n):
    t = n
    for i in range(n-1, -1,-1):
        if s[i] == '.':
            break
        else:
            t -= 1
    s = s[:t]
    n = len(s)
    return s,n

def main():
    n = int(input())
    s = input()
    res = 0
    s1 = s
    n1 = n
    res1 = 0
    s,n = cutw(s,n)
    s,n = cutb(s,n)
    for i in range(10):
        if n>0:
            s = '.'+s[1:]
            res += 1
            s,n = cutw(s,n)
            s,n = cutb(s,n)
        else:
            break
    res += min(s.count('.'),s.count('#'))
    s1,n1 = cutw(s1,n1)
    s1,n1 = cutb(s1,n1)
    for i in range(10):
        if n1>0:
            s1 = s1[:n1-1] + '#'
            res1 += 1
            s1,n1 = cutw(s1,n1)
            s1,n1 = cutb(s1,n1)
        else:
            break
    res1 += min(s1.count('.'),s1.count('#'))
    print(min(res,res1))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

S0 = S[0]
L = []
count = 1

for i in range(1,N):
    if S[i-1]!=S[i]:
        L.append(count)
        count =1

    else:
        count +=1
    if i ==N-1:
        L.append(count)

Numw =0
Numb =0

if S0 == '.':
    if S[-1] =='.':
        for i in range(1,len(L)):
            if i%2 == 0:
                Numw +=L[i]

            else: 
                Numb +=L[i]
        print(min(Numw,Numb))
    else:
        for i in range(1,len(L)-1):
            if i%2 ==0:
                Numw +=L[i]
            else:
                Numb +=L[i]
        print(min(Numb,Numw))
            

else:
    if S[-1]=='.':
        for i in range(len(L)):
            if i%2 ==0:
                Numb += L[i]
            else:
                Numw += L[i]
        print(min(Numb,Numw))

    else:
        for i in range(len(L)-1):
            if i%2 ==0:
                Numb += L[i]
            else:
                Numw += L[i]
        print(min(Numb,Numw))

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
S = input()
# 右全部#
b = []
w = []
for i in range(N):
    if S[i] == '#':
        b.append(i)
    if S[i] == '.':
        w.append(i)

kouho = []
for i in range(0,N+1):
    cost = 0
    #iから左を.、右を全部＃にする事を考える
    cost += i - bisect.bisect_right(w,i)
    cost += len(b) - bisect.bisect_right(b,i)
    
    if cost >= 0:
        kouho.append(cost)

print(min(kouho))

Submission status: Wrong Answer

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

S = S.lstrip('.').rstrip('#')
print(min(S.count('.'), S.count('#')))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if s.count("#")==0 or s.count(".")==0:
    print(0)
    exit()
bi=s.index("#")
wi=n-s[::-1].index(".")
if wi<bi:
    print(0)
    exit()
bc=s[bi:wi].count("#")
print(bi,wi)
print(min(bc,wi-bi-bc))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
try:
    first_black = S.index('#')
    target = S[first_black:]
    length = N - first_black
    black = target.count('#')
    print(min(black, length - black))
except ValueError:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
s=input()
ans = 0
kuro = [0]*(n+1)
siro = [0]*(n+1)
if n==1:
    ans=0
if n ==2:
    if s=="#.":
        ans=1
else: 
    for i,j in enumerate(s[::-1]):
        if j==".":
            kuro[i+1]=kuro[i]+1
        else:
            kuro[i+1]=kuro[i]
    for i,j in enumerate(s):
        if j == "#":
            siro[i+1]=siro[i]+1
        else:
            siro[i+1]=siro[i]
            
ku = np.array(kuro[::-1])
si = np.array(siro)
print(np.min(ku+si))

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
S = input()
# 右全部#
b = []
w = []
for i in range(N):
    if S[i] == '#':
        b.append(i)
    if S[i] == '.':
        w.append(i)

kouho = []
for i in range(0,N+1):
    cost = 0
    #iから左を.、右を全部＃にする事を考える
    cost += i - bisect.bisect_right(w,i)
    cost += len(b) - bisect.bisect_right(b,i)
    
    if cost >= 0:
        kouho.append(cost)

print(kouho)
print(min(kouho))

Submission status: Wrong Answer

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

white = 0
black = 0

if S[N-1] == "#":
  N = N-1

if S[0] ==".":
  N = N-1

for i in range(N):
  if S[i] == "#":
    black +=1
  else:
    white +=1



print(min(white,black))