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

#.......######
# a[n] = n個目より左にある#の数
# b[n] = n個目より右にある.の数

a = [0] * (N+2)
b = [0] * (N+2)

cnt = 2
for x in S:
    if x == "#":
        a[cnt] = a[cnt-1] + 1
    else:
        a[cnt] = a[cnt-1] 
    cnt += 1

cnt =N
Sinv = S[::-1]
for x in S:
    if x == ".":
        b[cnt] = b[cnt+1] + 1
    else:
        b[cnt] = b[cnt+1] 
    cnt -= 1



c = []

for index in range(N+2):
    c.append(a[index] + b[index])
c[0] = 999999

print(min(c))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
print(S.count("#."))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

a = S.count("#")
b = S.count(".")

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

print(min(a - cnt, b - cnt))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    s = s.split('#', 1)[-1]
    print(s.count('.'))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=list(input()[:-1])
b=S.count(".")
w=N-b
j= "#" if w>b else "."
c=0
for i in range(N):
  if S[i]!=j:
    S[i]=j
    c+=1
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())  # 数値入力
str = list(input())  # 一文字ずつ格納
newstr = []
new1str = []
for i in range(n):
    if str[i] == "#":
        new1str = str[i:]
        break

n1 = len(new1str)
for i in range(n1):
    if new1str[n1-1-i] == ".":
        newstr = new1str[:n1-i]
        break

if len(newstr) == 0:
    print(0)
else:
    print(min(newstr.count("."), newstr.count("#")))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cw=0
cb=0

m=0

for j in reversed(range(N)):
    if s[j]=="#":
        m=m+1
    else:
        break

for i in range(N-m):
    if s[i]==".":
        cw=cw+1
    if s[i]=="#":
        cb=cb+1

print(min(cw,cb))

Submission status: Wrong Answer

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

check_black_stone = False
check_white_stone = False
change_counter_typeA = 0
change_counter_typeB = 0


for stone_color in S:
    if check_black_stone and stone_color == ".":
        change_counter_typeA += 1
    elif stone_color == "#":
        check_black_stone = True

for stone_color in S[::-1]:
    if check_white_stone and stone_color == "#":
        change_counter_typeB += 1
    elif stone_color == ".":
        check_white_stone = True

result = change_counter_typeA if change_counter_typeA < change_counter_typeB else change_counter_typeB
print(result)

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
    elif str(S[i]) == "#" and str(S[i-1])==".":
        cnt1 += 0
    elif str(S[i]) == "#" and str(S[i-1])=="#":
        cnt1 += 0
    elif str(S[i]) == "." and str(S[i-1])==".":
        cnt1 += 0

print(cnt1)

Submission status: Wrong Answer

Solution code:
def main():
    N=int(input())
    line = list(input())
    flag = False
    cnt_W = 0
    cnt_B = 0
    for i in range(N):

        if line[N-i-1] ==".":
            flag = True
        if flag == True:
            if line[N-i-1] ==".":
                cnt_W +=1
            else:
                cnt_B +=1

    return min(cnt_W,cnt_B)

print(main())

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    n = 0b10000
    ans = 0
    for s in S:
        #print("{0:0100b}".format(n))
        n<<=1
        if s == "#":
            n += 0b1
        if n & 0b11 == 0b10:
            ans += 1
            n = n&0b00|0b01
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

haichi = a[1]
prev_haichi = '.'
count = 0
for each_haichi in haichi:
    if prev_haichi == '#' and each_haichi == '.':
        count += 1
        prev_haichi = '#'
    else:
        prev_haich = each_haichi
print(count)

Submission status: Wrong Answer

Solution code:
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
s = list(IS())
count = 0
if len(s) == 1:
    print(0)
    exit()
for i in range(len(s)):
    if i == 0 and s[i] == '#' and s[i+1] == '.':
        s[i] = '.'
        count += 1
    elif i == len(s)-1:
        break
    elif s[i-1] == '.' and s[i] == '#' and s[i+1] == '.':
        count += 1
        s[i] = '.'
    elif s[i-1] == '#' and s[i] == '#' and s[i+1] == '.':
        count += 1
        s[i+1] == '#'
print(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):
  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(stones_list)

count_0 = 0
count_1 = 0

if len(stones_list) == 2 and '#' in stones_list[::-1]:
  print(0)
  exit()

for i in range(len(stones_list)):
  if i % 2 == 0:
   count_0 += len(stones_list[i])
  else:
   count_1 += len(stones_list[i])

if count_0 > count_1:
  print(count_1)
else:
  print(count_0)

Submission status: Wrong Answer

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

i=0
num=0
while s[i]==".":
    num+=1
    i+=1
    if i == n:
        break
#  ..##.#..
n = s.count(".")
ans = n-num
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
count = 0
flag = True
start = 1

while flag:
    for i in range(start,N):
        if S[i] == '.':
            if S[i-1] == "#":
                S[i-1] = "."
                count += 1
                start = i
                break
        if i == N-1:
            flag = False

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# coding: UTF-8

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

b = S.count("#")
w = S.count(".")
if b == 0 or w == 0:
    print("0")
elif b <= w:
    print(b)
else:
    print(w)

Submission status: Wrong Answer

Solution code:
import numpy as np

dic={'.':0,'#':1}
N=int(input())
S=np.array([dic[i] for i in input()])

if S.sum()==0:
    print(0)
elif S.sum()==N:
    print(0)    
else:
    for i,j in enumerate(S):
        if j==1:
            print((S[i:]!=1).sum())
            break

Submission status: Wrong Answer

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

post = ''
ans=0
data=[]

left = [0 for _ in range(len(s))]
right = [0 for _ in range(len(s))]

tmp=0
for i in range(len(s)):
    if s[i]=='#':
        tmp+=1
    elif tmp!= 0:
        left[i]=tmp
        tmp=0

tmp=0
for i in range(len(s)):
    if s[n-i-1]=='.':
        tmp+=1
    if n-i-1-1 >=0 and s[n-i-1-1]=="#":
        right[n-i-1] = tmp
        tmp=0

# print(left)
# print(right)

for i in range(n):
    if left[i]!=0:
        ans += min(left[i],right[i])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = S[::-1]

a = 0
count = 0
for s in S:
  if s == ".":
    count += 1
  else:
    a += count
    count = 0

print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
 
res = 0
for i in range(len(S)-1):
    if S[i] == '#' and S[i+1] == '.':
        if i+2 <= len(S)-1:
            if S[i+2] == '.':
                S[i] = '.'
                res += 1
                continue
        res += 1
        S[i+1] = '#'

print(res)

Submission status: Wrong Answer

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

if '.' not in S or '#' not in S:
    print(0)
    exit()

index = 0
for i in range(0,len(S)):
    if S[i] == '#':
        index = i
        break

cou=0
for i in range(index + 1,N):
    if S[i] == ".":
        cou += 1

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

cou2 = 0
for i in range(0,index2):
    if S[i] == "#":
        cou2 +=1

print(min(cou,cou2))

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番目が白い石

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

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

flag = False
flag2 = True
for i in range(n):
    if not flag:
        if s[i] == ".":
            flag = True
    elif flag:
        if s[i] == "#":
            flag2 = False
            break
if flag2:
    print(0)
else:
    print(min(w_count, b_count))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s = input()
dot = re.sub('#\.+', '.', s)
n_dot = len(s) - len(dot)
sharp = re.sub('#+\.', '#', s)
n_sharp = len(s) - len(sharp)
print(n_dot) if n_dot < n_sharp else print(n_sharp)

Submission status: Wrong Answer

Solution code:
import re

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

print(len(re.findall("#.", s)))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
start = S.find("#")
if start == -1:
    print("0")
else:
    di = {".":"0","#":"1"}
    S_bin = int("0b"+S[start:].translate(str.maketrans(di)), 0)
    a = int("0b"+"1"*int(N-start) ,0)
    print(bin(a^S_bin).count("1"))

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("#")
z = 0
o = 0
l = 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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
# . = しろ
# # = 黒
# #の横に.がないようにしたい
# #の横に.があったら#を.に変える
# or #の横に.があったら.を#に変える

# when do you replace now char to .
# 

# テストケース
"""
11
#..#.##.##.
.....######
"""
# => .....# = 2

def inorderReplace(S , N): 
    S = list(S)
    cnt = 0
    for i in range(N - 1) : 
        nowChar = S[i]
        nextChar = S[i + 1]
        if nowChar == "#" and nextChar == "." : 
            cnt += 1
            if i + 2 >= N - 1 : 
                S[i + 1] = "#"
            else : 
                nextNextChar = S[i + 2]
                if nextNextChar == "." : 
                    S[i] = "."
                else : 
                    S[i] = "$"
    return cnt

cnt = inorderReplace(S , N)
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = [0,0]

for i in range(len(s)):
	cnt[(s[i] == "#")] += 1
print(min(cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
answ = S[0]
ansb = S[0]
cntw = 0
cntb = 0
for i in range(1, N):
  if answ[-1]=='#' and S[i]=='.':
    answ+='#'
    cntw+=1
  else:
    answ+=S[i]
  
  if ansb[-1]=='.' and S[i]=='#':
    ansb+='.'
    cntb+=1
  else:
    ansb+=S[i]
    
print(min(cntw,cntb))

Submission status: Wrong Answer

Solution code:
x = int(input())
st = list(input())
count = 0

for i in range(x - 1):
    if((st[i] == '#') and(st[i + 1] == '.')):
        count += 1
        st[i + 1] = '#'

print(count)

Submission status: Wrong Answer

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

r = S.count(".")
l = n - r

print(min(r, l))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
S1 = [s for s in S]
sharp = S.count("#")
dot = S.count(".")
ans1 = 0
for i in range(N-1):
    if S[i] == "#" and S[i+1] == ".":
        S[i+1] = "#"
        ans1 += 1

ans2 = 0
for i in range(1, N)[::-1]:
    if S1[i] == "." and S1[i-1] == "#":
        S1[i-1] = "."
        ans2 += 1
ans1 = min(dot, ans1)
ans2 = min(sharp, ans2)
print(min(ans1, ans2))

Submission status: Wrong Answer

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

array = [0]

before = S[0]
add = 0

for s in S:
	if before == s:
		array[-1] = array[-1] + 1
	else:
		array.append(1)
	before = s

if S[0] == '.':
	array.pop(0)

result = 0
for i in range(len(array)):
	if i % 2:
		continue
	if i + 1 >= len(array):
		break
	result += min(array[i],array[i+1])

print(result)

Submission status: Wrong Answer

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

i = s.find("#")
a = s[i:].count(".")
b = s.count("#")

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

Submission status: Wrong Answer

Solution code:
# https://tenka1-2019-beginner.contest.atcoder.jp/tasks/tenka1_2019_c

import itertools
from collections import Counter
import bisect

def main():
    N = int(input())
    S = list(input())
    # print(S)

    if S.count('.') == N or S.count('#') == N:
        print(0)
        exit()

    first = -1
    for i in range(len(S)):
        if S[i] != '.':
            first = i
            break

    # print(S[first:])
    next_s = list(reversed(S[first:]))
    # print(next_s)
    last = -1
    for i in range(len(next_s)):
        if next_s[i] != '#':
            last = i
            break
    if last == -1: # all black
        print(0)
        exit()

    next_s = list(reversed(next_s[last:]))
    # print(next_s)
    # exit()
    next_s += '#'
    ans = 0
    black_count = 0
    white_count = 0
    for v in next_s:
        if v == '#':
            if white_count > 0:
                if white_count >= black_count:
                    ans += black_count
                else:
                    ans += white_count
                black_count = 0
                white_count = 0
            black_count += 1
        else:
            white_count += 1

    print(ans)
    # 全部黒か全部白
    # print(min(next_s.count('.'), next_s.count('#')))

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] = "."
        ans += 1
print(ans)

Submission status: Wrong Answer

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

cnt = 0
for i in S:
    if i == '.':
        cnt += 1
    else:
        break

ANS1 = S[cnt:].count('.') 

cnt = 0
newS = ''.join(list(reversed(S)))
for i in newS:
    if i == '#':
        cnt += 1
    else:
        break

ANS2 = newS[cnt:].count('#') 

print(min(ANS1, ANS2))

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

N = int(input())
S = str(input())
Sarray = list(S)
Sarraynum = []

#白0
for i in range(len(Sarray)):
    if Sarray[i] == '.':
        Sarraynum.append(0)
    else:
        Sarraynum.append(1)

a = 2 * len(Sarraynum)
for i in range(len(Sarraynum)):
    black2white = 0
    white2black = len(Sarraynum) - i - 1
    for j in range(i):
        black2white += Sarraynum[j]
        if black2white + white2black >= a:
            break
    for j in range(i + 1, len(Sarraynum)):
        white2black -= Sarraynum[j]
        if black2white + white2black >= a:
            break
    
    if black2white + white2black < a:
        a = black2white + white2black


print(a)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

B = list(itertools.accumulate(S))

MIN = 10000000
cnt = []
for i in range(N):
    cnt.append(B[i] + N - B[N-1] + B[i] - i - 1)
    # MIN = min(MIN, cnt)
MIN = min(cnt)
print(MIN)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
S=S+'9'
ans=0
for i in range(N):
    if S[i]=='#' and S[i+1]=='.':
        cntj=0
        for j in range(i,-1,-1):
            if S[j]=='#':
                cntj+=1
            else:
                break
        cntk=0
        for k in range(i+1,N):
            if S[k]=='.':
                cntk+=1
            else:
                break
        if cntj < cntk:
            ans += cntj
        else:
            ans += cntk
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())

a=0
f = False
for i in range(len(S)-1):
    if (S[i]=='#') & (S[i+1]=='.'):
        if f:
            S[i]='.'
            f = False
        else:
            S[i+1]='#'
            f = True
        a += 1
print(a)

Submission status: Wrong Answer

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

def inverse(num, index, first):
    offset = 0
    if first == '*':
        offset = 1
    count = 0
    for n, i in enumerate(num):
        if n <= index and n % 2 == offset:
            count += i
        elif n > index and n % 2 != offset:
            count += i
    return count

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

if len(num) == 1:
    print(0)
else:
    minlist = []
    for i in range(len(num)):
        minlist.append(inverse(num, i, first))
    print(min(minlist))

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)
    answer = S.count('.')
print (answer)

Submission status: Wrong Answer

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

cou_b = 0
cou_w = 0

for i in range(N):
    if S[i]=='#':
        cou_b = S[i:].count('.')
        break
for i in range(N-1,-1,-1):
    if S[i]=='.':
        cou_w = S[:i].count('#')
        break
print(min(cou_b,cou_w))

Submission status: Wrong Answer

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

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

while i<len(s):
  b = 0
  while i<len(s) and s[i] == '#':
    b+=1
    i+=1
  w = 0
  while i<len(s) and s[i] == '.':
    w+=1
    i+=1
  r += min(b,w)

print(r)

Submission status: Wrong Answer

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

for i, s in enumerate(S):
    if s == '#':
        n = S[i:].count('.')
        break
    else:
        n = 0
for i, s in enumerate(reversed(S)):
    if s == '#':
        m = S[i:].count('#')
        break
    else:
        m = 0
print(min(n, m))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

try:
    i=s.index("#")
except:
    i=0

print s[i:].count(".")

Submission status: Wrong Answer

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

#初めて#がきたらそのあとの.はすべて変更しないといけない
found_first_sharp = False
change_cnt = 0
for i in range(len(S)):
    if S[i] == '.':
        if found_first_sharp:
            #S[i] = '#'
            change_cnt += 1
    else:
        if not found_first_sharp:
            found_first_sharp = True

print(change_cnt)

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

print(min(cc, N-cc))

Submission status: Wrong Answer

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

def inverse(num, index, first):
    offset = 0
    if first == '*':
        offset = 1
    count = 0
    for n, i in enumerate(num):
        if n <= index and n % 2 == offset:
            count += i
        elif n > index and n % 2 != offset:
            count += i
    return count

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

print(num)

if len(num) == 1:
    print(0)
else:
    minlist = []
    for i in range(len(num)):
        minlist.append(inverse(num, i, first))
    print(min(minlist))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
S1 = S[:]
S2 = S[:]
S3 = S[:]
S4 = S[:]
output1 = 0
output2 = 0
output3 = 0
output4 = 0

for i in range(N):
    if S1[i] == "." :
        S1[i] = "#"
        output1 += 1
for j in range(N):
    if S2[j] == "#":
        S2[j] == "."
        output2 += 1

flag = 0
for k in range(N):
    if (S3[k] == ".") and (flag==1):
        S3[k] == "#"
        output3 += 1
    if (S3[k] == "#") and (flag==0):
        flag = 1

flag = 0
for l in range(N):
    if (S4[N-1-l] == "#") and (flag==1):
        S4[N-1-l] == "."
        output4 += 1
    if (S4[N-1-l] == ".") and (flag==0):
        flag = 1

output = min(output1,output2,output3,output4)
print(output)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n = int(input())
s = input()
a = list(s)

shiro = 0
kuro = 0
flg = False
for i in range(n):
    if s[i] == '#':
        if i != n - 1:
            kuro += 1
        flg = True
    else:
        if flg:
            shiro += 1
mx = min(kuro, shiro)
print(mx)

Submission status: Wrong Answer

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

if N == 1 :
    ans = 0
elif "#" not in S[:-1] :
    ans = 0
else :
    s = S.find("#")
    a = S[s:].count(".")
    b = S[:-1].count("#")
    ans = min(a,b)
print(ans)

Submission status: Wrong Answer

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

ans=s.count(".")
if n==ans:
    print(0)
    sys.exit()
for i in range(len(s)):
    if s[i]==".":
        continue
    else:
        print(ans-i)
        break

Submission status: Wrong Answer

Solution code:
a = [input() for i in range(2)]
print(a[1].count('#.'))

Submission status: Wrong Answer

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

if n == 1:
    print(0)
elif n == 2:
    if s[0]=="#" and s[1]==".":
        print(1)
else :
    t = s[0]
    r = []
    cnt = 1
    for i in range(1, n):
        if t == s[i]:
            cnt += 1
        else :
            r.append(cnt)
            cnt = 1
            t = s[i]
    
    r.append(cnt)
    
    if len(r) == 1:
        print(0)
        
    else :
        ans = 0  
        if len(r) % 2 == 0:
            for i in range(0, len(r), 2):
                if r[i] > r[i+1]:
                    ans += r[i+1]
                else :
                    ans += r[i]
        else :
            for i in range(0, len(r)-1, 2):
                if r[i] > r[i+1]:
                    ans += r[i+1]
                else :
                    ans += r[i]    
        print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
d = n - s[::-1].find('.') - 1
c = s[:d].count('#')
d2 = s.find('#')
c2 = s[d2:].count('.')
print(c2)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
k = -1
for n,i in enumerate(S):
    if i=="#":
        k = n
        break
if k ==-1:
    print(0)
else:
    t =  sum([1 if i=="." else 0 for i in S[k:]])
    print(min(t,len(S[k:])-t))

Submission status: Wrong Answer

Solution code:

# coding: utf-8
# Your code here!

n = int(input())
 
lines = list(input())
 
 
count = 0
for line in lines:
    if line == ".":
        count+=1
    else:
        break
 
total = lines.count('.')
 
ans1 = total-count
 
count = 0
lines = lines[::-1]
for line in lines:
    if line == "#":
        count+=1
    else:
        break
total = lines.count('#')
ans2 = total-count

print(min(ans1,ans2))

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_left(w,i)
    cost += int(len(b)) - bisect.bisect_right(b,i)
    kouho.append(cost)

print(min(kouho))

Submission status: Wrong Answer

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

res = float("inf")

if "#" not in S or "." not in S:
    res = 0

counts = []
counts.append((0, 0))
a, b = 0, 0
for s in S:
    if s == "#":
        a += 1
    elif s == ".":
        b += 1
    counts.append((a, b))

for i in range(N):
    res = min(res, counts[i + 1][0] + counts[-1][1] - counts[i + 1][1])

print(res)

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]

indexes = [i for i, x in enumerate(s) if x == '.']

cnt = 0
for i in indexes:
    if s[i-1] == '#':
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

flg = False
cnt_w = 0
for s in S:
    if not flg:
        if s=='#':
            flg = True
    else:
        if s=='.':
            cnt_w += 1

flg = False
cnt_b = 0
for s in S[::-1]:
    if not flg:
        if s=='.':
            flg = True
    else:
        if s=='#':
            cnt_b += 1
print(min(cnt_w, cnt_b))

Submission status: Wrong Answer

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

first_w = 10 ** 6
last_b = 10 ** 6

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

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

change_num1 = 0
change_num2 = 0
S = "s" + S
if first_w < 10 ** 6:
    change_num1 -= 1
    for s in S[:first_w]:
        if s == "#":
            change_num1 += 1
    for s in S[first_w:]:
        if s == ".":
            change_num1 += 1

if last_b < 10 ** 6:
    for s in S[:last_b]:
        if s == "#":
            change_num2 += 1
    for s in S[last_b:]:
        if s == ".":
            change_num2 += 1

print(min(change_num1, change_num2))

Submission status: Wrong Answer

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

trial_num = int(input())
stones = list(input())

turn_white_stones = 0
turn_black_stones = 0
count_white_start = False
count_black_start = False

for i in range(trial_num):
    if(count_white_start == False):
        if(stones[i] == "#"):
            count_white_start = True
    else:
        if(stones[i] == "."):
            turn_white_stones += 1

    if(count_black_start == False):
        if(stones[trial_num-i-1] == "."):
            count_black_start = True
    else:
        if(stones[trial_num -i-1] == "#"):
            turn_black_stones += 1

print(min(turn_black_stones, turn_white_stones))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
if S == ['#'] * N or S == ['.'] * N:
    print(0)
    exit()

for i in range(N - 1, -1, -1):  # #->.
    if S[i] == '.':
        num1 = i
        break

for j in range(N):  # .->#
    if S[j] == '#':
        num2 = j
        break

ans1 = S[:num1].count('#')
ans2 = S[num2 + 1:].count('.')
print(min(ans1, ans2))

Submission status: Wrong Answer

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

black_count = 0
white_count = 0
right_white_pos=0
for i in range(N):
    if(S[i]=="."):
        white_count+=1
        right_white_pos=i
    else:
        black_count+=1

counter = 0
for i in range(N):
    if(i<right_white_pos):
        if(S[i]=="#"):
            counter +=1

print(min(white_count, black_count, counter))

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
if ans > N/2:
  print(N-ans)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import re

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

s = re.sub('^\.*([#\.]+)', r'\1', s)
print(0 if '#' not in s else s.count('.'))

Submission status: Wrong Answer

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

if len(S) == 0:
	print(0)
else:
	for n in range(N):
		if S[n:n+2] == "#." :
			M = n+1
			break
		else:
			M = len(S)+1
	print( S[M:].count("."))

Submission status: Wrong Answer

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

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


shirodeta = False
kurocount = 0
if S[-1] == "#":
    for stone in reversed(S):
        if not shirodeta and stone == "#":
            continue

        if stone == ".":
            shirodeta = True

        if stone == "#":
            kurocount += 1
else:
    kurocount = S.count("#")

print(min(cnt, kurocount))