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 = input()

#.#

S = S[::-1]
tmp = 0
ans = 0

for s in S:
    if s == "#":
        tmp += 1
    else:
        ans += tmp
        tmp = 0
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c1 = 0
for i in range(N - 1, -1, -1):
    if S[i] == ".":
        c1 = i
        break
c2 = N - 1
for i in range(N):
    if S[i] == '#':
        c2 = i
        break
a = S[:c1 + 1].count(".")
b = S[:c1 + 1].count("#")
cc = S[c2:].count("#")
d = S[c2:].count(".")
ans = min(a, b, cc, d)
print(ans)

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
            if i == n-1:
                si.append(count)
        else:
            si.append(count)
            count = 1
            flag = 1
    else:
        if s[i] == '#':
            count += 1
            if i == n-1:
                k.append(count)
        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:
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
        q=ll.count("#")
        ccount=z
        if q<z:
                ccount=q
print(ccount)

Submission status: Wrong Answer

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

# 全ての.をカウント
all_dots = S.count('.')

# 全ての#をカウント
all_sharps = S.count('#')

# #の左端～右端内の.をカウント=#左端までの文字数をall_dotsから引く
ho_dots = 0
for i in range(N):
    if S[i] == '#':
        ho_dots = i
        break
part_dots = all_dots - ho_dots

# .の右端～左端内の#をカウント=.右端までの文字数をall_sharpsから引く
ho_sharps = 0
for i in range(N - 1, -1, -1):
    if S[i] == '.':
        ho_sharps = N - 1 - i
        break
part_sharps = all_sharps - ho_sharps

print(min(all_dots, all_sharps, part_dots, part_sharps))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
_ = 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:
def main():
    N = int(input())
    S = input()
    length = 0
    for i in range(1, N):
        if S[i-1] == '#' and S[i] == '.':
            length += 1
    print(length)
main()

Submission status: Wrong Answer

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

i = s.find("#")
if i < 0:
  i = 0
a = s[i:].count(".")
j = s.rfind("#")
b = s[:j].count("#") + s[j:].count(".")

if a < b:
  print(a)
else:
  print(b)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
cur=0
lis=["" for i in range(N)]
lis[cur]=S[0]
for c in S[1:]:
	ss=lis[cur]
	if c==".":
		lis[cur]=ss+"."
	else:
		if ss[-1]=="#":
			lis[cur]=ss+"#"
		else:
			cur+=1
			lis[cur]="#"
def counting(sss):
	curb=sss.find("#")
	curw=sss.rfind(".")
	return min(sss[:curw+1].count("#"),sss[curb:].count("."))

c=0
for l in lis:
	if l=="":
		break
	else:
		a=counting(l)
		c+=a
print(c)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
S = input()
b = 0
w = 0
stone = ""
num = []
for k, v in groupby(S):
  stone += k
  num.append(len(list(v)))
if stone[0] == ".":
  stone = stone[1:]
  num = num[1:]
try:
  if stone[-1] == "#":
    stone = stone[:-1]
    num = num[:-1]
except:
  pass
if stone:
  for i, s in enumerate(stone):
    if s == "#":
      b += num[i]
    else:
      w += num[i]
print(min(b,w))

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
#print(N,S)

if not "#" in S or not "." in S:
  print(0)
else:
  print(S.count("."))

Submission status: Wrong Answer

Solution code:
input()
s = input()
ans = s.count("#.")
ans += s.count("##..")

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
c = 0
b = s.count('#')
for i in range(n-1):
 if s[i] == '#' and s[i + 1] == '.':
  c += 1
  s[i +1] = '#'

print(min(c,b))

Submission status: Wrong Answer

Solution code:
import re


N = int(input())
S = input()
re_bwbbb = re.compile(r'#\.+#*$')
re_bw = re.compile(r'#\.+')
replace = 0

while len(S) > 0:
    match = re_bwbbb.search(S)
    if match is None:
        break

    sub_word = match.group(0)
    pattern = re_bw.match(sub_word).group(0)
    if pattern.count('.') > pattern.count('#'):
        replace += pattern.count('#')
    else:
        replace += pattern.count('.')
    
    S = S[0:-len(sub_word)]

print(replace)

Submission status: Wrong Answer

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

  ans = 10**15
  a = s.count(".")
  b = s.count("#")
  sharp = []
  dot = []
  tp = 1
  if a == n:
    print("0")
    exit()
  elif n == 1:
    print(b)
    exit()
  else:
    for i in range(n-1):

        if s[i] == s[i+1]:
           tp += 1
               
        if s[i] != s[i+1]:
            if s[i]==".":
                dot.append(tp)
                sharp.append(0)
            else:
                dot.append(0)
                sharp.append(tp)
            tp = 1
        if i == n-2:
           if s[i+1]==".":
                dot.append(tp)
                sharp.append(0)
           else:
                dot.append(0)
                sharp.append(tp)
           tp = 1
    
    e = len(sharp)
    ans = min(b-sharp[-1],a-dot[0])
    #print(dot,sharp)
    #print(ans)
    for i in range(e):
      do = dot[i]
      sh = sharp[i]
      a += do
      b += sh
      ans = min(ans,min(b-sharp[-1],a-dot[0]))
      
    #print(dot,sharp)     
    print(ans)
solve()

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    S = list(input())
    
    count_sharp = S.count('#')
    count_dot = S.count('.')
    # print(count_sharp, count_dot, count_sharp < count_dot)
    count = 0

    for i in range(1, len(S)):
        
        # print(S, end=' ')
        one = S[i-1]
        two = S[i]
        
        if count_sharp < count_dot:
            if (one == '#') and (two == '.'):
                count += 1
                S[i-1] = '.'
            elif (one == '#') and (two == '#'):
                S[i-1] = '.'
                count += 1
        else:
            if (one == '#') and (two == '.'):
                count += 1
                S[i-1] = '.'
            # elif (one == '#') and (two == '#'):
            #     S[i-1] = '.'
            #     count += 1
        # print(count, end=' ')
        # print(S)

    print(count)
    # #..#.#....##...# -> (.)..(.).(.)....(.)(.)...#

main()

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline())
S = input()

#S = list(S)
S_1 = S
S_2 = S
S_1 = list(S_1)
S_2 = list(S_2)

cnt_cb = 0
cnt_cw = 0
for i in range(len(S_1)-1):
#    print(S_1[i],S_1[i+1])
    if S_1[i]=="#" and S_1[i+1]==".":
        S_1[i+1] = "#"
        cnt_cb += 1
#        print("change")


for i in range(len(S_2)-1):
#    print(S_2[i],S_2[i+1])
    if S_2[i]=="#" and S_2[i+1]==".":
        S_2[i] = "."
        cnt_cw += 1
#        print("change")

print(min(cnt_cb,cnt_cw))

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:
N=int(input())
S=input()
S=list(S)

count0=0
count1=0
count2=0

for j in range(N):
    if S[j]=='.':
        count0+=1
    else:
        break

for i in range(count0,N):
    if S[i]=='#':
        count1+=1
    elif S[i]=='.':
        count2+=1

if count1==0 or count2==0:
    print('0')
else:
    if count1<count2:
        print(count1)
    elif count1>count2:
        print(count2)
    else:
        print(count1)

Submission status: Wrong Answer

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

X = [0 if x == '#' else 1 for x in S] # 0:black 1:white
Y = list(reversed(X))

if 0 not in X or 1 not in X:
    ans = 0 
else:
    idx = X.index(0) # first black
    a = sum(X[idx:]) # white to black
    idx2 = Y.index(1) # last white
    b = (N - idx) - a - idx2
    ans = min(a, b)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sr = s[::-1]
left_b = 0
right_w = 0

loop = n//2
for i in  range(loop):
    if s[i] == "#":
        left_b += 1
    if sr[i] == ".":
        right_w += 1
if left_b == 0 or right_w == 0:
    if len(s)%2 == 0:
        print(0)
    elif s[n//2] == s[n//-1] or s[n//2] == s[n//2+1] :
        print(0)
    else:
        print(left_b + right_w)
else:
    print(left_b + right_w)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
blacknum = []
whitenum = []
cnt = 0
now = 0
blackcnt = 0
whitecnt = 0

for i in range(N):
    if now == 0 and S[i] == '#':
        whitenum.append(whitecnt)
        blackcnt += 1
        now = 1
    elif now == 1 and S[i] == '.':
        blacknum.append(blackcnt)
        whitecnt += 1
        now = 0
    elif now == 0 and S[i] == '.':
        whitecnt += 1
    else:
        blackcnt += 1

if now == 0:
    whitenum.append(whitecnt)
else:
    blacknum.append(whitecnt)
if len(whitenum) == len(blacknum):
    whitenum.append(whitecnt)

ans = 0
for i in range(len(blacknum)):
    if blacknum[i] <= (whitenum[-1] - whitenum[i]):
        ans = blacknum[i]
    else:
        ans += whitenum[-1] - whitenum[i]
        break

print(min(whitenum[-1], ans))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
num = []
bl = 0
wh = 0
for i in range(n):
    if s[i] == "#":
        num.append([i,wh])
        bl += 1
    else:
        wh += 1
min = n
if len(num) > 0:
    for i in range(len(num)):
        temp = (num[i][0] - num[i][1]) + (n - bl - num[i][1])
        if temp < min:
            min = temp
    print(min)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
N = int(input())
s=list(input())
ii = 9999999999
count_a = 0
count_b = 1
for index, i in enumerate(s):
  if i == '#' and ii == 9999999999:
    ii = index
    continue;
  elif ii == 9999999999:
    continue;
  else:
    if i == '.':
      count_a+=1
    else:
      if index != N-1:
      	count_b+=1
      
print(min(count_a, count_b))

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

#left_count番目より右にある.の個数を数える

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

#right_count番目より左にある#の個数を数える

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:
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())

BLACK = '#'
WHITE = '.'

count = 0
for idx in range(len(S) - 1):
    if S[idx] == BLACK and S[idx + 1] == WHITE:
        if idx > 0:
            if S[idx - 1] == BLACK:
                S[idx + 1] = BLACK
            else:
                S[idx] = WHITE
        else:
            S[idx] = WHITE
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = 0
i=0

while(i<n and s[i] == "."):
	i+=1
for j in range(i,n):
	if(s[i] == "."):
		cnt+=1

print(cnt)

Submission status: Wrong Answer

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

start = len(s)
frag = False
i = 0
kuro = 0
while(i<len(s)):
    if(s[i] == "#"):
        kuro += 1
    if(s[i]=="#" and not(frag)):
        frag = True
        start = i
    elif(s[i]=="." and frag):
        start = i - 1
        i = len(s)
    i += 1

if(start == len(s)):
    print("0")
else:
    shiro = 0
    renzoku = 0
    for i in range(len(s)-start-1):
        if(s[i+start+1]=="."):
            renzoku = 0
            shiro += 1
        else:
            renzoku += 1
            kuro += 1
    if(kuro-renzoku<=shiro):
        print(kuro-renzoku)
    else:
        print(shiro)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count1 = 0
count2 = 0
for i in range(N-1):
    if S[i:i+2] == '#.':
        count1 += 1

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

print(min(count1, count2))

Submission status: Wrong Answer

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

s = list(s)

count = 0

for i in range(n-1):
    if s[i] != s[i+1]:
        s[i+1] = s[i]
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    N = int(input())
    S = input()

    if N == 1:
        print(0)
        return

    white, black = [], []
    cntw, cntb = 0, 0
    prev = S[0]
    for s in S:
        if prev != s:
            white.append(cntw)
            black.append(cntb)
            cntw, cntb = 0, 0
        if s == '.':
            cntw += 1
        else:
            cntb += 1
        prev = s
    white.append(cntw)
    black.append(cntb)

    ans = 0
    for i in range(len(black)-1):
        if black[i] and not black[i+1]:
            ans += min(black[i], white[i+1])
    print(ans)

input = lambda: stdin.readline().rstrip()
main()

Submission status: Wrong Answer

Solution code:
from __future__ import print_function
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


n=int(input())
S=list(input())

cnt_temp=0
stack=[]
cnt=0

# eprint(n)
# eprint(S)

# for i in range(n):
#     eprint(i)

    
for i in range(n):
    if S[i] == '.':
        cnt_temp+=1

for i in range(n-1):
    if S[i]=='#' and S[i+1]=='#':
        stack.append(i)
    elif S[i]=='#' and S[i+1]=='.':
        
        S[i]='.'
        cnt+=1
        while stack!=[]:
            temp=stack.pop()
            S[temp]='.'
            cnt+=1
        

print(min(cnt,cnt_temp))
            #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
f = 0
c = 0
for i, s in enumerate(S):
    if s == '#' and f == 0:
        f = 1
    elif s == '.' and f == 1:
        S = S.replace(s, '#')
        c += 1
print(c)

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
            if i == n-1:
                si.append(count)
        else:
            si.append(count)
            count = 1
            flag = 1
    else:
        if s[i] == '#':
            count += 1
            if i == n-1:
                k.append(count)
        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
print(smax)
kmax = sum(k) - ka
print(kmax)
ans = min(smax,kmax)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections

def solve():
    N=int(sys.stdin.readline().rstrip())
    S=list(sys.stdin.readline().rstrip())
    left=0
    right=N-1
    for i,c in enumerate(S):
        if c=='.':
            continue
        left=i
        break
    else:
        left=N
    for i in range(N-1,-1,-1):
        if S[i]=='#':
            continue
        right=i
        break
    else:
        right=-1
    #print(left,right)
    if left>right:
        return 0
    S=S[left:right+1]
    cnt=collections.Counter(S)
    #print(cnt)
    if cnt['.']>cnt['#']:
        return cnt['#']
    else:
        return cnt['.']

print(solve())

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
S = input()
b = 0
w = 0
stone = ""
num = []
for k, v in groupby(S):
  stone += k
  num.append(len(list(v)))
print(stone)
print(num)
if stone[0] == ".":
  stone = stone[1:]
  num = num[1:]
try:
  if stone[-1] == "#":
    stone = stone[:-1]
    num = num[:-1]
except:
  pass
if stone:
  for i, s in enumerate(stone):
    if s == "#":
      b += num[i]
    else:
      w += num[i]
print(min(b,w))

Submission status: Wrong Answer

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

b2=0
h2=0
for i in range(len(s)-1,-1,-1):
    if s[i]=="#" and h2!=0:
        b2+=1
    if s[i]==".":
        h2+=1
print(b2)

Submission status: Wrong Answer

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

countb = 0
countw = 0
check = -1
ans = []

for i in range(len(S)):
    if(S[i] == "#"):
        check = 1
        countb = countb + 1
    else:
        check = 0
        countw = countw + 1
    if(check == 1 and countw != 0):
        if(countb < countw):
            ans.append(countb)
        else:
            ans.append(countw)
        countb = 0
        countw = 0
    if(i == N-1):
        if(countb < countw):
            ans.append(countb)
        else:
            ans.append(countw)

print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
    
print(min(S[1:].count('.'), S[:-1].count('#')))

Submission status: Wrong Answer

Solution code:
import sys
a = []
for l in sys.stdin:
    a.append(l)

num = int(a[0])
haichi = a[1]
prev_haichi = '.'
black_count = 0
white_count = 0
white_count_mode = False
for i in range(num):
    each_haichi = haichi[i]
    if each_haichi == '#':
        black_count += 1
        if not white_count_mode:
            white_count_mode = True
    if each_haichi == '.' and white_count_mode:
        white_count += 1
    
print(min(black_count, white_count))

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")

l=[t,r]
x=[[k,len(list(v))]for k,v in groupby(s)]
ans=0
for i in range(len(x)):
    n,m=x[i]
    if n==".":
        r-=m
    else:
        t-=m
        ans+=m
        l.append(ans+r)
print(min(l))

Submission status: Wrong Answer

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

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

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


print min(ans1, ans2)

Submission status: Wrong Answer

Solution code:
"""
python3 a.py < input.txt
"""
import math
import itertools as it
import heapq

N=int(input())
S=input()
lb=None
for i in range(N):
    if S[N-i-1] == "#":
        lb=N-i-1
if lb==None:
    print(0)
    exit(0)
rw=None
for i in range(N):
    if S[i]==".":
        rw=i
if rw==None:
    print(0)
    exit(0)
nb=0
for i in range(lb, N):
    if S[i] == ".":
        nb = nb+1
nw=0
for i in range(0, rw):
    if S[i] == "#":
        nw = nw+1

print(min(nb, nw))

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
S=list(input())
ans1=0
tmp=0
ans2=0
A=copy.copy(S)
for i in range(N-1):
  if A[N-i-1]=='#' and A[N-i-2]=='#':
    A.pop(N-i-1)
    tmp+=1
  else:
    break
for i in range(N-tmp-1):
  if A[i]=='#':
    ans1+=1
for i in range(N-1):
  if S[i]=='#':
    if S[i+1]=='.':
      S[i+1]='#'
      ans2+=1
print(min(ans1,ans2))

Submission status: Wrong Answer

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

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

count=0 #black
flag=-1 #first black
for i in range(n):
    if s[i]=="#":
        count+=1
        if flag==-1:
            flag=i
if count==0:
    ans=0
elif count==n:
    ans=0
else:
    a=count-flag
    b=n-count
    ans=min(a,b)




print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
c=0
b=0
p=0
for i in range(n):
  if s[i]=="."and s[i-1]=="#":
    c+=b
    b=0
  elif s[i]=="#":
    b+=1
  else:
    b=0
for i in range(n):
  if s[i]==".":
    p+=1
  else:
    break

if c>(n/2):
  print(n-c-p)
else:
  print(c)

Submission status: Wrong Answer

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

count_s = 0
count_d = 0
for i in range(1,n):
    if s[-i] == '#':
        count_s += 1
    else:
        break

for i in range(n):
    if s[i] == '.':
        count_d += 1
    else:
        break

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

print(min(sharp_num,dot_num))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
sr = S[::-1]
ans = sr[0]
cnt = 0
if S.count('#')>S.count('.'):
  word = '#'
else:
  word = '.'

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

Submission status: Wrong Answer

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

x=0
a=0
b=0

for i in range(N):
    if S[i]==".":
        a+=1
    else:
        b+=1

if a==N or b==N:
    print("0")
elif a>=b:
    x=N-a
    print(x)
else:
    x=N-b
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = 0
w = 0

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

if(b > w):
    print(w)
else:
    print(b)

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    S = list(input())
    
    count_sharp = S.count('#')
    count_dot = S.count('.')
    print(count_sharp, count_dot, count_sharp < count_dot)
    count = 0

    for i in range(1, len(S)):
        
        # print(S, end=' ')
        one = S[i-1]
        two = S[i]
        
        if count_sharp < count_dot:
            if (one == '#') and (two == '.'):
                count += 1
                S[i-1] = '.'
            elif (one == '#') and (two == '#'):
                S[i-1] = '.'
                count += 1
        else:
            if (one == '#') and (two == '.'):
                count += 1
                S[i-1] = '.'
            # elif (one == '#') and (two == '#'):
            #     S[i-1] = '.'
            #     count += 1
        # print(count, end=' ')
        # print(S)

    print(count)
    # #..#.#....##...# -> (.)..(.).(.)....(.)(.)...#

main()

Submission status: Wrong Answer

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

counter = 0

List = []
for i in range(n):
    List.append(s[i])

counter = 0
for i in range(n-1):
    if List[i] == '#' and List[i+1] == '.':
        List[i+1] = '#'
        counter += 1

print(counter)

Submission status: Wrong Answer

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

i = 0
while i<len(s) and s[i] == '.':
  i+=1

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

Submission status: Wrong Answer

Solution code:
stones = [raw_input() for i in range(2)][1]
if "#" not in stones:
    print 0
else:
    counter = 0
    for ind, i in enumerate(stones, start=0):
        if i == "#":
            break
    for i in stones[ind:]:
        if i == ".":
            counter += 1
    print(counter)

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('#') + reverse_s[:reverse_s.index('#')].count('.')
    print(min(cmp1,cmp2))

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 = "#"

    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
#idx = s.find("#.")

rs = "".join(list(reversed(s)))

idx = rs.find(".#")

if idx != -1:
  ans = min(rs[idx+1:].count("#"), rs.count("."))


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

target = S[0]
cnt = 0
for i in range(1, N):
    if target == '#' and S[i] == '.':
        cnt += 1
        target = '#'  # 黒に変える
        continue

    if S[i] == '#':
        target = '#'
    else:
        target = '.'

cnt_2 = 0
aim = S[-1]
for i in range(N-1, -1, -1):
    if aim == '.' and S[i] == '#':
        cnt_2 += 1
        aim = '.'
        continue

    if S[i] == '#':
        aim = '#'
    else:
        aim = '.'

print(min(cnt, cnt_2))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c=S.count('#')
if ('.' in S) & ('#' in S):
	s=S.index('.')
	p=S.index('#')
	k=S[p::]
	a=k.count('.')
	if (s==0)&(a==0):
		print(0)
	elif a>c:
		 print(c)
	else:
		 print(a)
else:
	print(0)

Submission status: Wrong Answer

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

def run(N, S):
    num_black= S.count('#')
                       
    if num_black == 0:
        return 0
    elif num_black == N:
        return 0

    end_sharp = 0
    for i in reversed(S):
        if i == '.':
            break
        end_sharp += 1

    startpos = 0
    for i in S:
        if i == '#':
            break
        startpos+=1
    
    nums = N - startpos - end_sharp
    if nums > num_black * 2:
        return num_black - end_sharp
    else:
        return nums - num_black + end_sharp
 
print(run(N, S))

Submission status: Wrong Answer

Solution code:
n=2
string_list=[input() for i in range(n)]
c=0
new=''
a=0
b=0
f=0
for stone in string_list[1]:
    if stone=='.' and c==0:
        continue
    elif stone=='#':
        c+=1
        a+=1
        f+=1
    elif stone=='.':
        b+=1
        f=0

if b>=(a-f):
    print(a-f)
else:
    print(b)

Submission status: Wrong Answer

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

cnt = 0
items = list(s)
num1 = items.count('#')
num2 = items.count('.')

ans1 = min(num1, num2)

ind = s.find('.')
sub1 = s[:ind]
sr = ''.join(reversed(list(s)))
ind = sr.find('#')
sub2 = sr[:ind]

num1 = sub1.count('#')
num2 = sub2.count('.')
ans2 = num1 + num2


print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())
if set(S) == {'#'} or set(S) == {'.'}:
    print(0)
    sys.exit()
first_b = S.index('#')
b_count = S.count('#')
w_count = S[first_b:].count('.')
if b_count < w_count:
    if S[-1] == '#':
        print(b_count-1)
    else:
        print(b_count)
else:
    print(w_count)

Submission status: Wrong Answer

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

if "#" not in S:
	print("0")
	exit(0)

mostLeftBlack=S.index("#")

tmpS=S[mostLeftBlack:]

targ="."

ans=tmpS.count(targ)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black_exist_num_w = 0
num_b = 0
black = False
for i in range(N):
    if S[i] == '#':
        black = True
        num_b += 1

    elif S[i] == '.':
        if black == True:
            black_exist_num_w += 1

if num_b <= black_exist_num_w:
    print(num_b)
else:
    print(black_exist_num_w)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s = list(s)
t = s
c = 0
for i in range(n-2):
  if t[i] == '#' and t[i+1] == '.' and t[i+2] == '#':
    t[i] = '.'
    c+=1
    
for i in range(n-1):
  if t[i] == '#' and t[i+1] == '.':
    t[i+1] = '#'
    c+=1

print(c)

Submission status: Wrong Answer

Solution code:

def count(s):
    rest = ''
    for i, char in enumerate(s):
        if char == '.':
            continue
        else:
            rest = s[i:]
            break

    b = len(rest.replace('.', ''))
    w = len(rest.replace('#', ''))

    if b > w:
        return w
    else:
        return b


def main():
    _ = int(input())
    s = input()  # '#.#' -> '###'

    print(count(s))


main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
S=S+'#'
sc=0
tc=0
ans=0
for i in range(N+1):
    if(tc!=0 and S[i]=='#'):
        if(sc>tc):
            ans+=tc
        else:
            ans+=sc
        tc=0
        sc=0
    if(sc!=0 and S[i]=='.'):
        tc+=1
    elif(tc==0 and S[i]=='#'):
        sc+=1
print(str(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
replace_ans = -1
while replace_ans != 0:
    replace_ans = S.count("#.")
    S = S.replace("#.", "#")
    ans += replace_ans
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = 0
i=0

while(i<n and s[0] == "."):
	i+=1
for j in range(i,n):
	if(s[i] == "."):
		cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
#N=3
#s=".######."
#s=[s[i] for i in range(len(s))]
N=int(input())
s=input()
s=[s[i] for i in range(len(s))]
tmp=[]
for i in range(len(s)):
    count=0
    for j in range(len(s)):
        if j<=i:
            if s[j]=="#":
                count=count+1
        if j>i:
            if s[j]==".":
                count = count+1
    tmp.append(count)
       
print(min(tmp))

Submission status: Wrong Answer

Solution code:
N = int(input()) 
S = input() 
 
#.......######
# a[n] = n個目より左にある#の数
# b[n] = n個目より右にある.の数
 
a = [0] * (N+2)
b = [0] * (N+3)
 
cnt = 2
for x in S:
    if x == "#":
        a[cnt] = a[cnt-1] + 1
    else:
        a[cnt] = a[cnt-1] 
    cnt += 1
 
cnt =N+1
Sinv = S[::-1]
for x in S:
    if x == ".":
        b[cnt] = b[cnt+1] + 1
    else:
        b[cnt] = b[cnt+1] 
    cnt -= 1
b[cnt] = b[cnt+1]
 
 
 
c = []
 
for index in range(N+2):
    c.append(a[index] + b[index])
c[0] = 999999
 
print(min(c))