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:
# -*- coding: utf-8 -*-
"""
AtCoder C
"""
 
def main():
    N=input()
    S=list(map(str,input().split()))[0]
    tmp=False
    num=0
    for s in S:
        # print(s,tmp)
        if s=="#":
            tmp=True
        elif s=="." and tmp:
            num+=1

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

    print(min(num,num2-bl))
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

t =  sum([1 if S[i]=='#' else 0 for i in range(N)])
print(min(t,N-t))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

num_black = S.count('#')
num_white = S.count('.')


if num_black > num_white:
    cnt = 0
    prev = S[0]
    for i in range(1, len(S)):
        if prev == '#' and S[i] == '.':
            S[i] = '#'
            cnt += 1
        prev = S[i]
else:
    cnt = num_black
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
whi=0
bla=0
c1=0
for i in S:
    if i=="#":
        break
    c1+=1
for i in S[::-1]:
    if i==".":
        whi+=1
    else:
        bla+=1
c2=0
for i in S[::-1]:
    if i==".":
        break
    c2+=1
print(min(whi-c1,bla-c2))

Submission status: Wrong Answer

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

s = list(S)

change = False
i = 0
count = 0
for c in s:
    if c == '#':
        change = True
    elif change == True:
        count += 1
        change = False
    i += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
f = S.find('#')
black = S.count('#',f)
white = S.count('.',f)
if black < white:
    print(black)
else:
    print(white)

Submission status: Wrong Answer

Solution code:
input()
s = input()
print(s[s.find('#')+1:].count('.'))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
try:
    a=s[::-1].index("#")
    b=s.index("#")
except:a=b=0
count=0
for i in range(b+1,n-a):
    if s[i]=="#":count+=1
print(count)

Submission status: Wrong Answer

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

init_white=True
num_whites=0
num_blacks=0
tmp=0
for c in s:
    if init_white and c == ".":
        continue
    init_white = False

    if c == ".":
        num_whites += 1
        num_blacks += tmp
        tmp = 0
    
    if c == "#":
        tmp += 1

print(min(num_whites, num_blacks))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
count_white = 0
flag = False

for s in S:
  if s == "#" and not flag:
    flag = True
  elif s == "." and flag:
    count_white += 1
    
flag = False
count_black = 0
for s in reversed(S):
  if s == "." and not flag:
    flag = True
  elif s == "#" and flag:
    count_black += 1
print(min(count_white, count_black))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
T = S.copy()

ans1,ans2 = 0,0
for i in range(N):
  if(i != 0):
    if((S[i-1] == '#')and(S[i] == '.')):
      ans1 += 1
      S[i] = '#'
    if((T[i-1] == '#')and(T[i] == '.')):
      ans2 += 1
      T[i] = '.'
ans = min(ans1,ans2)
print(ans)

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] == '.':
        if (i+2) < n:
            if s[i+2] == '#':
                s[i+1] = '#'
            else:
                s[i] = '.'
        else:
            s[i+1] = '#'
        ans += 1
print(ans)

Submission status: Wrong Answer

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

count = 0
while '#.' in S:
    temp = S.replace('#.', '*')
    count += temp.count('*')
    temp = temp.replace('*', '##')
    S = ''.join(temp)

print(count)

Submission status: Wrong Answer

Solution code:
_ = input()
S = input()

print(S.count('#.'))

Submission status: Wrong Answer

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

k = 0
flag = s.count("#") > s.count(".")

if flag:
    for i, c in enumerate(s):
        if c == "#":
            if i != len(s) - 1 and s[i + 1] == ".":
                k += 1
else:
    for i, c in enumerate(s):
        if c == ".":
            if i != len(s) - 1 and s[i + 1] == "#":
                k += 1

print(k)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
for i in range(n):
    s.append("#")
count = 0
for i in range(n):
    if s[i] == "#" and s[i+1] == ".":
        c = 1
        for j in range(n):
            if s[i+j+2] == ".":
                c += 1
            else:
                break
        count += c
print(count)

Submission status: Wrong Answer

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


black=0
white=0
for st in s:
  if st=="#":
    black=black+1
  else:
    white=white+1
change=0

if black>white:
  for i in range(n-1):
    if s[i]=="#" and s[i+1]==".":
      change=change+1
      s[i+1]=="#"

else:
  for i in range(n-1):
    if s[i]=="#" and s[i+1]==".":
      change=change+1
      s[i]=="."

print(change)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
white = [s=="." for s in S]
black = [s=="#" for s in S]
ans = 10000000000
for i in range(N):
    a = sum(black[:i])
    b = sum(white[i:])
    ans = min(ans,a+b)
print(ans)

Submission status: Wrong Answer

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

S_list = list(S)
firstBlack = N
countStone = 0
for i in range(0, N):
  if(S_list[i] == "#"):
    firstBlack = i
    break

for i in range(firstBlack, N):
  if(S_list[i] == "."):
    countStone = countStone + 1
    
print(countStone)

Submission status: Wrong Answer

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

def all_black():
    first_black = -1
    for i in range(n):
        if s[i] == '#':
            first_black = i
            break

    result = 0
    if first_black > -1:
        for i in range(first_black, n):
            if s[i] == '.':
                result += 1

    return result

def all_white():
    result = 0
    for i in range(n):
        if s[i] == '#':
            result += 1
    
    return result

result = min([all_black(), all_white()])
print(result)

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:]
            count = S_right.count(".")
            break

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import string

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

left_black = s.find('#')
right_white = s.rfind('.')

# print(left_black)
# print(right_white)
# print(s[left_black+1:])
# print(s[:right_white])
# print(s[left_black+1:].count('.'))
# print(s[:right_white].count('#'))

print(min(s[left_black+1:].count('.'), s[:right_white].count('#')))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
black = s.count('#')
if black > 0:
    del s[:s.index('#')]
    white = s.count('.')
    print(white if white<=black else black)
else:
    print('0')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

w = s.count('.')
b = s.count('#')
print(min(w, b))

Submission status: Wrong Answer

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

count = 0
for i in range(len(s)-1):
    if s[i] == '#' and s[i+1] == '.':
        if i == 0:
            s[i] = '.'
            count += 1
        elif i == len(s) -2:
            s[i+1] = '#'
            count += 1
        else:
            if s[i-1] == '.':
                s[i] = '.'
            else:
                s[i+1] = '#'
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
s = list(ns())
i = 0
j = n - 1
count = 0
f1 = 0
f2 = 0
while(i < j - 1):
    if s[i] == '#':
        f1 = 1
    else:
        i += 1
    if s[j] == '.':
        f2 = 1
    else:
        j -= 1
    if f1 == 1 and f2 == 1:
        s[i], s[j] = s[j], s[i]
        count += 2
        f1 = 0
        f2 = 0
        i += 1
        j -= 1
if s[i] != s[j]:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
last = s[-1]
count = 0

for c in reversed(s[:-1]):
	if(last == '.' and c == '#'):
		count += 1
		last = '.'
	else:
		last = '#'

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
s2 = list(s)
cnt = 0
cnt2 = 0
for i in range(n):
    if n == 0:
        pass
    else:
        if s[i-1] == "#" and s[i] == ".":
            s[i] = "#"
            cnt += 1
for i in range(n):
    if n == 0:
        pass
    else:
        if s2[i-1] == "#" and s2[i] == ".":
            s2[i-1] = "."
            cnt2 += 1
print(min(cnt, cnt2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
first = True
ans = 0
for i in range(N):
  if first:
    if S[i] == '#':
      first=False
  else:
    if S[i] == '.':
      ans += 1
print(ans)

Submission status: Wrong Answer

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

lsts=list(s)

ans=0

for i in range(n-1):
    if lsts[i]=="#" and lsts[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)
ans = 0
if index != -1 :
  for i in range(index, n) :
      if s[i] == "." : ans +=1
print (ans)

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnta = s.count("#")
cntb = s.count(".")
ans = min(cnta,cntb)
for i in range(N):
	if s[i] == "#":
		tmp = i
		ans = min(ans,N-(cnta+i))
		break
print(ans)

Submission status: Wrong Answer

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

siro = 0
k = 0
for i in range(n):
  if k >= 1 and slis[i] == ".":
    siro += 1
  if slis[i] =="#":
    k += 1

kuro = 0
s = 0
for j in range(n-1,-1,-1):
  if s >= 1 and slis[j] == "#":
    kuro += 1
  if slis[j] == ".":
    s += 1
    
print(min(kuro,siro))

Submission status: Wrong Answer

Solution code:
a = int(input())
s = list(input())
ans2 = s.count('#')
ans = 0
for i in range(a-1):
    if(s[i] == "#" and s[i+1] == "."):
        ans += 1
        s[i+1] = "#"
        
print(min(ans2, ans))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
S = input()
b = 0
w = 0
for i, (k, v) in enumerate(groupby(S)):
  if i == N-1:
    if k == "#":
      break
  v = len(list(v))
  if k == "#":
    b += v
  else:
    w += v
print(min(b,w))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
t=list(s)
s.append("0")
t.append("0")
ans1=0
ans2=0
for i in range(n):
  if s[i]=="#" and s[i+1]==".":
    s[i+1] = "#"
    ans1 += 1
for j in range(n-1):
  if t[j]=="#":
    ans2 += 1
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
black = 0
white = 0
count = 0
find = True

for i in reversed(range(0,n)):
    if find == True and s[i] == '#':
        black += 1
    elif s[i] == '.':
        white += 1
        find = True
    if black == white:
        count += white
        white = 0
        black = 0
        find = False

print(count)

Submission status: Wrong Answer

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

# print(S.count("#."))


# 最後の.から前の#は置き換える、でいいはず
first_black = S.find("#")
if (first_black == -1) :
    first_black = 0

last_white = S.rfind(".")
if (last_white == -1) :
    last_white = N-1

S2 = S[first_black:last_white+1]
b_to_w = S2.count("#")
w_to_b = S2.count(".")
print(min(b_to_w,w_to_b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
min_cnt = len(s)
for i in range(len(s)+1):
    tmp1 = s[:i]
    tmp2 = s[i:]
    #print("----")
    #print(tmp1)
    #print(tmp2)
    tmp_cnt = tmp1.count('#')+tmp2.count('.')
    print(tmp_cnt)
    if min_cnt > tmp_cnt:
        min_cnt = tmp_cnt
print(min_cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
'''
k=int(input())
a,b,c=map(int,input().split())
a=[int(i) in range(n)]
a=[0]*n
for i in range(n):
    a.append(int(i))
'''
pre=0
b=[0]*n
w=[0]*n

for i in range(n):
    if s[i]=='#':
        cc=1
    else:
        cc=0
    b[i]=pre+cc
    pre+=cc
tb=b[n-1]
for i in range(n):
    w[i]=n-(i+1)-(tb-b[i])

#print(s,b,w)
ans=n
for i in range(n):
    ans=min(ans,b[i]+w[i])
    
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
l=list(input())
a=l.count(".")
b=l.count("#")
ans=min(a,b)
print(ans)

Submission status: Wrong Answer

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

s = list(S)
s1 = s.count(".")
for i in range(N-1, -1, -1):
    if s[i] == "#":
        s.pop(i)
    else:
        break

s2 = s.count("#")

print(min(s1, s2))

Submission status: Wrong Answer

Solution code:
import re


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

match = re.match('^\.*#', S)
if match:
    first_match = len(match.group(0))
else:
    print(0)
    exit()

print(S[first_match:].count('.'))

Submission status: Wrong Answer

Solution code:
def solve():
  N = int(input())
  S = input()
  foundBlack = False
  black, b, white = 0, 0, 0

  for stone in S:
    if stone == '#':
      if not foundBlack: foundBlack = True
      b = b + 1
    else:
      if not foundBlack: continue
      white = white + 1
      black = black + b
      b = 0

  print(white, black)
  return min(black, white)

print(solve())

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
print(s.count("#."))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import scipy as sp

def main():
    while True:
        try:
            il = [input() for i in range(2)]
            N = int(il[0])
            S = il[1]
            print(S.count('#.'))
        except:
            break

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if N == 1 :
    ans = 0
else :
    a = S.find("#")
    if a == -1 :
        ans = 0
    else :
        ans = S[a:].count(".")
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(str(input()))
l=[]
w=0
b=0
wl=[]
bl=[]
for i in range(n):
    if s[i]==".":
        w+=1
    else:
        b+=1
    wl.append(w)
    bl.append(b)
        
ans=[]
for i in range(n):
    ans.append(bl[i]+wl[n-1]-wl[i])
print(min(ans))

Submission status: Wrong Answer

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

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

first_white = S.find('.')
first_black = S.find('#')

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

# 2.黒い石よりも右側に白色の石が存在する場合
elif S[first_black:].find('.') > -1:
  cnt_white = S[first_black:].count('.')
  cnt_black = S[first_black:].count('#') + 1

  out = min(cnt_white,cnt_black)

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

print(out)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
print("0" if s.count("#") == 0 else s[s.index("#"):].count("."))

Submission status: Wrong Answer

Solution code:
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break
if S[-1] == '#':
    print(min(S.count('#')-1, S[left:].count('.')))
else:
    print(min(S.count('#'), S[left:].count('.')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
cou = 0
bef = S[0]
for i in range(1,N):
    if S[i]=='.' and bef=='#':
        cou+=1
    bef = S[i]
print(cou)

Submission status: Wrong Answer

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
n = ip()                                     #入力整数1つ
#a,b,c= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(3)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
p = 0
while a[p] == '.':
    p+=1
    if p == n: break
x,y = 0,0
for i in range(p,n):
    if a[i] == '#':x+=1
    else: y+=1
p = n-1
c,d = 0,0
while a[p] == '#':
    p-=1
    if p == -1: break
for i in range(p,-1,-1):
    if a[i] == '#': c+=1
    else:d+=1
print(min(x,y,c,d))

Submission status: Wrong Answer

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

white = 0
black = 0

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

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



print(min(white,black))

Submission status: Wrong Answer

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

f = 0
w = 0
b = 0
sb = '$'
for s in S:
    if s=='.' and sb=='#':
        f=1

    if f and s=='.':
        w+=1

    if s=='#':
        b+=1
    sb=s

print(min(w, b))

Submission status: Wrong Answer

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

flg = 0
idx = 0
for i in S:
    if i == '#':
        flg = 1
        break
    idx += 1

if flg == 1:
    a = S[idx+1:].count('.')
    b = S[idx:].count('#')
    if S[-1] == '#':
        for ct in range(1, N+1):
            if S[-ct] == '.':
                break
        b -= ct-1
    ans = min(a, b)

else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import re
import sys
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    S = ii(str)
    S = S[::-1]
    s = re.findall("#", S[S.find("#") + 1 :])
    return len(s)


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
for i in range(100):
    s.append("#")
count = 0
for i in range(n):
    if s[i] == "#" and s[i+1] == ".":
        c = 1
        for j in range(n):
            if s[i+j+2] == ".":
                c += 1
            else:
                break
        count += c
print(count)

Submission status: Wrong Answer

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

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
"""s = 0
while s < N and S[s] == "." :
    s += 1
for i in range(s, N):
    if S[i] == ".":
        ans += 1"""
print(ans)

Submission status: Wrong Answer

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


min_count=20000

for i in range(N):
    black_count=S[0:i+1].count("#")
    white_count=S[i+1:N].count(".")
    min_count = min(min_count, black_count+white_count)
    
print(min_count)

Submission status: Wrong Answer

Solution code:
stones_count = int(input())
input_str = input()

target = input_str[0]

def set_next_target(target_char):
  if target_char == '#':
    return '.'
  else:
    return '#'

stones = ''
stones_list = []

for i in range(stones_count):
  #print(input_str[i],target)
  if input_str[i] == target:
    stones = stones + target
  else:
    stones_list.append(stones)
    target = set_next_target(target)
    stones = target

stones_list.append(stones)
#print(len(stones_list))

if len(stones_list) == 1:
  print(0)
elif len(stones_list) == 3:
  print(1)
elif len(stones_list) %2 == 0:
  print(len(stones_list) // 2)
else:
  print(len(stones_list) // 2 - 1)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip().split()
s = s[0]

cnt = 0
for i in range(len(s)):
    if len(s) == i + 1:
        break

    if s[i] == '#' and s[i + 1] == '.':
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
cnt = 0
S_list = list(S)
for i in range(0,N-1):
    if S_list[i] != S_list[i+1]:
        if S_list[i] == "#":
            cnt += 1
            S_list[i+1] = "#"
        elif S_list[i] == ".":
            cnt += 1
            S_list[i+1] = "."
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
b,w = 0,0

if '#' not in S:
    print(0)
elif '.' not in S:
    print(0)
else:
    f = S.index('#')
    Sr = S[::-1]
    e = Sr.index('.')
    for i in range(f,N-e):
        if S[i] == '#':
            b += 1
        else:
            w += 1

    print(min(b,w))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

countW = 0
count_left_B = 0
countB = 0
for i in range(len(S)):
    if S[i] == ".":
        countW += 1
    else:
        countB += 1

for i in range(len(S)):
    if S[i] == "#":
        count_left_B += 1
    else:
        break

numW = countW
numB = countB - count_left_B

if numB > numW:
    print(numW)
else:
    print(numB)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
flag_b=0
sum_b=0
sum_w=0
for i in S:
    if i=="." and flag_b==1:
        sum_w+=1
    if i=="#" and flag_b==1:
        sum_b+=1
    if i=="#" and flag_b==0:
        flag_b=1
        sum_b+=1
if sum_w > sum_b:
    print(sum_b)
else:
    print(sum_w)

Submission status: Wrong Answer

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

kurodeta = False
cnt = 0
for stone in S:
    if not kurodeta and stone == ".":
        continue

    if stone == "#":
        kurodeta = True

    if stone == ".":
        cnt += 1

kurocount = S.count("#")

print(min(cnt, kurocount))

Submission status: Wrong Answer

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

# def transB(N,S):
#     ret = 0
#     for i in S:
#         if i == "#":
#             ret += 1
#     return ret
    
# def transW(N,S):
#     ret = 0

num_W = 0  
for i in S:
    if i == ".":
        num_W += 1
num_B = N - num_W

if num_W < num_B:
    print(num_W)
else:
    if S[N-1] == "#":
        print(num_B - 1)
    else:
        print(num_B)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    n = 0b0
    ans = 0
    for s in S:
        n<<=1
        if s == "#":
            n += 0b1
        if n & 0b10 == 0b10:
            ans += 1
            n = n>>2+(n&0b1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
black = s.count('#')
if black > 0:
    white = s.count('.')
    del s[:s.index('#')]
    print(white if white<=black else black)
else:
    print('0')

Submission status: Wrong Answer

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

W=S.count('.')
B=N-W
ans_1=min(W,B)

first_b=S.find('#')
S_w = S[0:first_b]
S_b = S[first_b:N]
ans_2 = S_w.count('#')+S_b.count('.')

print(min(ans_1,ans_2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ast  = s.count('.')
hash = s.count('#')

print(min(ast, hash))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
arg=0
for i in range(n):
    if s[i]=="#":
        arg=i
        break
ans=s[arg:].count(".")
ans_1=s.count("#")
print(ans if ans < ans_1 else ans_1-1 if s[-1]=="#" else ans_1)

Submission status: Wrong Answer

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

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:
#coding: utf-8
N = int(input())
S = list(input())
for i in range(N):
    if S[i] == "#":
        index = i
        break
ans = 0
for j in range(i, N):
    if S[j] == ".":
        ans += 1
print(ans)

Submission status: Wrong Answer

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

i = s.find('#')
j = s.count('.')

if i == -1:
    print(0)
else:
    print(j - i)

Submission status: Wrong Answer

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

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  S = input()

  current = '#'
  counts = {"#": 0, ".": 0}
  ans = 0
  for c in S:
    if c != current:
      current = c
      if current == '#':
        ans += min(counts["#"], counts["."])
        counts = {"#": 0, ".": 0}
    counts[c] += 1

  if current == ".":
    ans += min(counts["#"], counts["."])

  print(ans)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=0
ans2=0
now="."
now2="."
for i in s:
  if ans2<ans:
    now=now2
    ans=ans2
  if now=="#" and i==".":
    ans+=1
  else:
    now=i
  if now2=="#" and i==".":
    ans2+=1
    now2="."
  else:
    now2=i
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

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

ans = 10**6
blacks = [0 for i in range(N)]
black = 0
white = 0
for i in range(N):
    if S[i] == "#":
        black += 1

    else:
        white += 1
    blacks[i] = black

ans = min(black,white,ans)

# print(blacks)
for i in range(1,N):
    cnt = 0
    cnt += (N-i)-(blacks[N-i]-blacks[i])#black
    cnt += blacks[i-1]#white

    ans = min(ans,cnt)

print(ans)

Submission status: Wrong Answer

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

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

num_white = 0
num_black = 0
ansb = 0
answ = 0
for i in range(N):
    if S[i] == '.':
        ansb = num_black
        num_white += 1
    else:
        answ = num_white
        num_black += 1

print(min([num_white - answ, ansb, num_white]))

Submission status: Wrong Answer

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

a=s.count(".")
tmp=s.rfind(".")
if tmp==-1:
  print(0)
  exit()
b=s[0:tmp].count("#")
print(min(a,b))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
for i in range(N):
    if S[0] == S[i] :
        continue
    else:
        count +=1
if (N / 2) <= count:
    print(N - count)
else:
    print(count)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i] == '#':
        first_black = i
        break
    first_black = i

cnt = 0
if first_black == N-1:
    cnt = 0
else:
    for i in range(first_black,N,1):
        if S[i] == '.':
            cnt += 1

print(cnt)

Submission status: Wrong Answer

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


count1 = 0
found = False
for ss in s:
    if found:
        if ss == '.':
            count1 += 1
        else:
            pass
    else:
        if ss == '.':
            pass
        else:
            found = True



count2 = 0
found = False
for ss in s[::-1]:
    if found:
        if ss == '#':
            count2 += 1
        else:
            pass
    else:
        if ss == '#':
            pass
        else:
            found = True


print(min(count1, count2))

Submission status: Wrong Answer

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

num_black= S.count('#')
                   
if num_black == 0:
    print('0')
elif num_black == N:
    print('0')
else:    
    startpos = 0
    for i in S:
        if i == '#':
            break
        startpos+=1
        
    print(N - startpos - num_black)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
left_w = n
for i in range(n):
    if s[i] == "#":
         left_w = i
         break
ans_w = 0
for i in range(n):
    if s[i] == ".":
        ans_w += 1

s = s[::-1]
right_b = n
for i in range(n):
    if s[i] == ".":
         right_b = i
         break
ans_b = 0
for i in range(n):
    if s[i] == "#":
        ans_b += 1

print(min(ans_w-left_w, ans_b-right_b))