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()
count = 0

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

Submission status: Wrong Answer

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

if "." not in s or "#" not in s:
    print(0)
    exit()

f,f2 = 0,0
res,res2 = 0,0
for i,j in zip(s,reversed(s)):
    if f == 1 and i==".":
        res += 1
    if i=="#":
        f = 1
    if f2 == 1 and j=="#":
        res2 += 1
    if j==".":
        f2 = 1

else:
    print(min(res,abs(n-res)-1,res2,abs(n-res2)-1))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
white = '.'
black = '#'

cnt = 0
for i in S:
    if(i==black):
        break
    else:
        cnt += 1
#print(cnt)
#print(S)
S = S[cnt:]
#print(S)
chg_cnt = 0
for i in S:
    if(i==white):
        chg_cnt += 1
print(chg_cnt)

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

Submission status: Wrong Answer

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

counter = [[0,0] for i in range(N)]
count = 0
for i in range(N):
    if S[i] == '#':
        count += 1
    counter[i][0] = count

count = 0
for i in range(N)[::-1]:
    if S[i] == '.':
        count += 1
    counter[i][1] = count

mini = N
for i in range(N-1):
    if mini > counter[i][0] + counter[i+1][1]:
        #print(i, counter[i][0] + counter[i+1][1])
        mini = counter[i][0] + counter[i+1][1]

white = S.count('.')
print(mini if white != 0 and white != N else 0)
#print(counter)

Submission status: Wrong Answer

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

num = 0
for i in range(n):
    try:
        if s[i] == '#' and s[i+1] == ('.'):
            num += 1
            s[i] = '.'
        else:
            pass
    except:
        break
num2 = 0
for i in range(n):
    try:
        if s[i] == '#' and s[i+1] == ('.'):
            num2 += 1
            s[i+1] = '#'
        else:
            pass
    except:
        break
print(min(num,num2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = s.find("#")
anum = s.count("#")
b = s.find(".")
bnum = n - anum


if a == -1 or b == -1:
    print(0)
elif "." in s[b+1:]:
    print(min(s[a:].count("."),anum,bnum))
else:
    print(min(s[a:].count("."),s[:b+1].count("#"),anum,bnum))
    #一番左の"#"から数えていくつ "." があるか
    #一番左の"."から数えていくつ"#"があるか

Submission status: Wrong Answer

Solution code:
import sys

N =  int(sys.stdin.readline())
S = sys.stdin.readline()[:-1]
res = 0

for i in range(N-1):
  if S.count('#') < S.count('.'):
    if S[-1] != '#':
      res = S.count('#')
    else:
      res = S.count('#') -1
  else:
    if S[0] != '.':
      res = S.count('.')
    else:
      res = S.count('.') - 1

print(res)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
S = input().strip()

def stone_cnt(idx):
  return S[:idx].count("#") + S[idx:].count(".")

left = 0
right = len(S) - 1

while left <= right:
  mid = (left + right) // 2
  if stone_cnt(left) > stone_cnt(right):
    left = mid + 1
  else:
    right = mid - 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
t = S.count(".")
if t == N:
    print(0)
    exit(0)

b = 0
for k in range(N):
    if S[k] == "#":
        b = k
        break
w = 0
for k in range(N):
    if S[k] == ".":
        w = k

print(min(S.count("."),S.count("#"),S[:w+1].count("#"),S[b:].count(".")))

Submission status: Wrong Answer

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

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

if num_W < num_B:
    if S[0] == ".":
        first_W = 0
        for j in S:
            if j == ".":
                first_W += 1
            else:
                break
        print(num_W - first_W)
    else:
        print(num_W)
else:
    if S[N-1] == "#":
        last_B = 0
        for j in S[::-1]:
            if j == "#":
                last_B += 1
            else:
                break
        print(num_B - last_B)
    else:
        print(num_B)

Submission status: Wrong Answer

Solution code:
input()
S = input()

if '#' in S:
    black = S.index('#')
    ans = [S[black:].count('#'), S[black:].count('.')]
    if ans[0] <= ans[1]:
        for c in S[::-1]:
            if c == '#':
                ans[0] -= 1
            else:
                break
        print(ans[0])
    else:
        print(ans[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=input()
sflag=0
a=0
b=0
c=0



for i in S:
    if i==".":
        a+=1
    if i=="#":
        b+=1
    if i=="#" and sflag==0:
        sflag=1
    if sflag==1:
        if i==".":
            c+=1


print(min(a,b,c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
first = n
for i in range(n):
  if (s[i] == '#'):
    first = i
    break
print(min(s[first:].count('.'), s[first:].count('#')))

Submission status: Wrong Answer

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

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

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

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

	print(ans)

	

	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
flag = 0
result = 0
for i in range(1,n):
    if s[i] == "." and s[i-1] == "#":
        flag = i
        if i == n-1:
            result += 1
    elif s[i] == "#" and s[i-1] == ".":
        if flag != 0:
            result += i-flag
            flag = 0
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
p = '.'
q = 0
for i in range(n):
    if p=='#' and s[i]=='.':
        q += 1
        p = s[i]
    else:
        p = s[i]
print(q)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s1 = '#'
i = 0
slis = []
ini = True

for s in S:
  if s == s1:
    i += 1
  if s != s1:
    if ini:
      slis.append(i)
      ini = False
    else:
      slis.append(i + 1)
    s1 = s
    i = 0

slis.append(i+1)

if S.startswith('.'):
  sum1 = sum(slis[2::2])
  sum2 = sum(slis[3::2])
else:
  sum1 = sum(slis[0::2])
  sum2 = sum(slis[1::2])

print(min(sum1, sum2))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
S = input()
col = "#."
hoge = 0
C = [0]
for i in range(N):
    if S[i] == col[hoge]:
        C[-1] += 1
    else:
        C.append(1)
        hoge = (hoge+1)%2
B,W =0,0
for i in range(math.floor(len(C)/2)):
    B += C[i*2]
    W += C[i*2+1]
if C[0] == 0:
    W -= C[1]
print(min(B,W))

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())
w = 0
b = 0
count = 0
white = ['.' for _ in range(n)]
black = ['#' for _ in range(n)]

for i in range(n):
    if s[i] != white[i]:
        w += 1
    if s[i] != black[i]:
        b += 1
l = 0
r = n - 1
while(l < r):
    if s[l] == '#':
        s[l] = '.'
        count += 1
        if l + 1 == r:
            break
    if s[r] == '.':
        s[r] = '#'
        count += 1
    l += 1
    r -= 1
print(min(w, b, count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if S[0] == "#" or S[-1] == ".":
  w = S.count(".")
  print(min(w, N - w))
else:
  bw = []
  for i in range(N):
    if i == 0 or S[i] != S[i - 1]:
      bw.append(1)
    else:
      bw[-1] += 1
  
  ans = float("inf")
  for i in range(len(bw)):
    tmp = 0
    for j in range(len(bw)):
      if j < i and j % 2 == 1:
        tmp += bw[j]
      elif j >= i and j % 2 == 0:
        tmp += bw[j]
      ans = min(ans, tmp)
  print(ans)

Submission status: Wrong Answer

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

cnts_b_from_r = [0 for i in range(N)]
cnts_w_from_l = [0 for i in range(-1,N)]

# count num for each color
lst = list(S)
last_black = 0
for i,val in enumerate(lst):
	if S[i] == "#":
		last_black += 1
	
	cnts_b_from_r[i] = last_black
	
lst.reverse
last_white = 0
for i,val in enumerate(lst):
	if val == ".":
		last_white += 1
	
	cnts_w_from_l[i] = last_white

min_val = N
for i in range(N):
	new_val = cnts_b_from_r[i] + cnts_w_from_l[N-(i+2)]
	min_val = min(new_val,min_val)

print(min_val)

Submission status: Wrong Answer

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

def f(i, j):
	if j >= i:
		return "#"
	else:
		return "."

ans = float("inf")
tmp = 0
for j in range(N):
	if S[j] != f(0, j):
		tmp += 1
ans = tmp
for i in range(1, N):
	if f(i, i) != S[i]:
		tmp += 1
	else:
		tmp -= 1
	if tmp < ans:
		ans = tmp
tmp = 0
for i in range(N):
	if S[i] == "#":
		tmp += 1
if tmp < ans:
	ans = tmp
print(ans)

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 = '.'
count = 0
for i in range(num):
    each_haichi = haichi[i]
    if prev_haichi == '#' and each_haichi == '.':
        count += 1
        prev_haichi = '#'
    else:
        prev_haichi = each_haichi
print(count)

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('#')
if first_b == -1:
  ans_2 = 0
else:
  S_w = S[0:first_b]
  S_b = S[first_b:N]
  ans_2 = S_w.count('#')+S_b.count('.')
  
S_rev = S[::-1]
first_w=S_rev.find('.')
if first_w == -1:
  ans_3 = 0
else:
  Srev_b = S_rev[0:first_w]
  Srev_w = S_rev[first_w:N]
  ans_3 = Srev_b.count('.')+Srev_w.count('#')


print(min(ans_1,ans_2,ans_3))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
for i in range(0,n) :
    if s[i] == '.' :
        c += 0
    elif s[i] == '#' :
        b = i
        break
s = s[i:n]
x = s.count('#')
y = s.count('.')
if x < y :
    print(x)
else :
    print(y)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
sp = s.find('#')
if sp != -1:
  s = s[sp:]
ep = s.rfind('.')
if ep != -1:
  s = s[:ep+1]
b = s.count('#')
w = s.count('.')
ans = b if b < w else w
print(ans)

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:]==0).sum())
            break

Submission status: Wrong Answer

Solution code:
import re

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

ans = len(re.findall("#.", s))

if s[-3:] == ".#." :
    ans-=1;

print(ans)

# .#.#.#.#.

Submission status: Wrong Answer

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

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

print(min(a, b))

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 k == 0 and 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 s == 0 and slis[j] == ".":
    s += 1

#print(siro,kuro)
print(min(kuro,siro))

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:
            count += 1
            S[i-1] = '#'
        # print(S)

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

main()

Submission status: Wrong Answer

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

W = '.'
B = '#'

print(min(S.count(W), S.count(B)))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

cnt = 0
pre = ''
for key, value in groupby(s):
    if pre == '':
        pre = key
        continue

    if pre == '#' and key == '.':
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sl = []
count = 0
state = 0
b = 0
w = 0
for i in range(n):
    if s[i] == "#":
        if state == 0:
            state = 1
            b += 1
        elif state == 1:
            b += 1
        elif state == 2:
            if b > w:
                count += w
                b = 1 + b + w
                w = 0
                state = 1
            else:
                count += b
                b = 1
                w = 0
                state = 1
    else:
        if state == 1:
            state = 2
            w += 1
        elif state == 2:
            w += 1

if state == 2:
    count += min([b,w])

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().rstrip()
s=[i for i in s]
count=0
prevhash=0
nextdot=0
countdot=0
counthash=0
countboth=0
ans=min(s.count('.'),s.count('#'))
flag=0
prev=s[0]
for i in s:
    if  i==prev:
        pass
    else:
        flag+=1
        prev=i
if flag==1:
    ans=0
print(ans)

Submission status: Wrong Answer

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

i = S.find('#')
if i < 0:
    print(0)
else:
    print(min(S[i:n].count('.'), S.count('#')))

Submission status: Wrong Answer

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

cnt = 0
for s in S:
    if s == ".":
        cnt += 1
    else:
        break
ws = S[cnt:]
w = ws.count(".")
bs = S[::-1]
cnt = 0
for s in bs:
    if s == "#":
        cnt += 1
    else:
        break
bs = bs[cnt:]
b = bs.count("#")
print(min(w, b))

Submission status: Wrong Answer

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

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

maekuro = len(S.split('#')[0])
usirosiro = len(S.split('.')[-1])
print(min(S[maekuro:].count('.'), S[:len(S)-usirosiro].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
	WB = S[M:].count(".")
	BW = S[M-1:].count("#")
	print(min(WB , BW))

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] == '.':
                if i > 0:
                    if S[i-1] != '#':
                        S[i] = '.'
                        res += 1
                        continue
                else:
                    S[i] = '.'
                    res += 1
                    continue

        res += 1
        S[i+1] = '#'

print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
import collections as coll
t = coll.Counter(s)
b1,w1=t["#"],t["."]

b = 0
w = 0
p = 0
q = 10 ** 18
for i in range(n):
    if s[i] == "#":
        b += 1
    else:
        w += 1
    
    p = b + w1 - w
    if p < q:
        q = p

print(q)

Submission status: Wrong Answer

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

flag = False
count = 0
for i in range(N):
    if S[i] == '#':
        flag = True
    elif flag is True:
            count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
S = input()
B,W = [],[]
key = '#'
i = 0

for s in S:
    if s == '#' and key == '.':
        W.append(i)
        i = 0
        key = '#'
    elif s == '.' and key == '#':
        B.append(i)
        i = 0
        key = '.'
    i += 1
W.append(i) if s == '.' else 0

ans = 0
for b,w in zip(B,W):
    ans += min(b,w)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

S = list(S)

cnt = 0
for i in range(len(S)):
    if i == len(S)-1:
        break
    elif S[i] == "#" and S[i + 1] == ".":
       cnt = cnt + 1
       
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
dp = [0 for i in range(N)]
b = 0
w = 0
flag1 = True
flag2 = True
for i in range(N):
    if flag1 and S[i] == '.':
        pass
    elif flag1:
        flag1 = False
        b += 1
    elif S[i] == '.':
        dp[i] = b
    else:
        b += 1

for i in reversed(range(N)):
    if flag2 and S[i] == '#':
        pass
    elif flag2:
        flag2 = False
        w += 1
    elif S[i] == '#':
        dp[i] = w
    else:
        w += 1
ans = float('inf')
for i in range(N-1):
    if (S[i] == '.' and S[i+1] == '#') or (S[i] == '#' and S[i+1] == '.'):
        if dp[i] == 0 or dp[i+1] == 0:
            ans = min(ans,dp[i]+dp[i+1])
        else:
            ans = min(ans,min(dp[i],dp[i+1]))
if ans == float('inf'):
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black = S.count('#')
white = S.count('.')
count = 0
S.append(0)

if black > white:
    for i in range(0,N):
        if S[i]=='#' and S[i+1]=='.':
            S[i+1]='#'
            count += 1
else:
    for i in range(0,N):
        if S[i]=='#' and S[i+1]=='.':
            S[i]='.'
            count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = S.rstrip('#')
S = S.lstrip('.')
N = len(S)
cnt = S.count(".")
if cnt == N:
  print(0)
elif cnt > N/2:
  print(N-cnt)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
import re
a = [input() for i in range(2)]
cnt = a[1].count('#.')
txt = re.sub('#\.',"##",a[1])
while txt.count('#.') > 0:
    cnt += txt.count('#.')
    txt = re.sub('#\.',"##",txt)

print(cnt)

Submission status: Wrong Answer

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

m = ['#', '.']
m1 = ['#', '.', '#']
m2 = ['#', '.', '#']
m3 = ['#', '#', '.']
m4 = ['.', '#', '.']

count = 0
for i in range(N):
    if S[i:i+2] != m:
        continue

    flag = True
    if i>=0 and i<= N-3:
        if S[i:i+3] == m1:
            count +=1
            S[i] = '.'
            flag = False
        elif S[i:i+3] == m2:
            count += 1
            S[i] = '.'
            flag = False
    if flag == False or i==0:
        continue


    if S[i-1:i+2] == m3:
        S[i+1] = '#'
        count += 1
    elif S[i-1:i+2] == m4:
        S[i] = '.'
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy

n = int(input())
char = input()

char_list = numpy.array(list(char),dtype=str)
all_write = numpy.full(n,".",dtype=str)
all_black = numpy.full(n,"#",dtype=str)
mix = numpy.full(n,".",dtype=str)
mix[-1] = "#"

print(min(n - sum(all_black == char_list),n - sum(all_write == char_list),n - sum(mix == char_list)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

if len(S) == 1:
    print(ans)
elif len(S) == 2:
    if S == ['#', '.']:
        print("1")
    else:
        print("0")
elif len(S) == 3:
    for i in range(len(S)-1):
        if S[i] == '#' and S[i+1] == '.':
            ans += 1
    print(ans)
            
else:
    for i in range(1, len(S)-2):
        if S[i] == '#' and S[i+1] == '.':
            if S[i+2] == '.':
                if S[i-1] == '.':
                    S[i] = '.'
                if S[i-1] == '#':
                    S[i+1] = '#'
            else:
                S[i+1] = '#'
            ans += 1
            
    if S[-2:] == ['#', '.']:
        ans += 1
    if S[:2] == ['#', '.']:
        ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
black =False
w_num = 0
b_num =0
for i in range(N):
    if black:
        if S[i]==".":
            w_num +=1
    
    if S[i]=="#":
        black =True
        b_num +=1
        
ans = min(w_num,b_num,N-b_num)
print(ans)

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)))
n = len(stone)
if stone[0] == ".":
  stone = stone[1:]
  num.remove(num[0])
try:
  if stone[-1] == "#":
    stone = stone[:-1]
    num.remove(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 = input()

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

print(min(num1, num2))

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
if S3[0]=="#":
    S3[0]="."
    output3 += 1
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
if S4[N-1]==".":
    S4[N-1]="#"
    output4 += 1
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:
n = int(input())
s = str(input())

count = 0

while s.count("#.") != 0:
    old_count = s.count("#.")
    s = s.replace("#.", "..")
    new_count = s.count("#.")
    count += old_count - new_count

print(count)

Submission status: Wrong Answer

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

cnt = 0
S = S[::-1]
if '#' in S:
    idx = S.index('#')
    prev = S[idx]
    for i in S[idx:]:
        if prev == i:
            cnt +=1
        else:
            break

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans1 = 1e7
ans2 = 1e7
f = False
for i in range(N-1):
    if S[i:i+2] == "#.":
        ans1 = S[i:].count(".")
        f = True
        break

for i in range(N-1):
    j = N - i
    if S[j-2:j] == "#.":
        ans2= S[:j-1].count("#")
        f = True
        break

print(min(ans1, ans2) if f else 0)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
w_cnt=0
b_cnt=0
for i in range(n):
    if s[i] == "#":
        b_cnt += 1
    else:
        w_cnt += 1

print(min([w_cnt,b_cnt]))

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

  st = 0
  for i in range(N):
    if S[i] != '.':
      st = i
      break
  ed = N
  for i in range(N):
    if S[N - 1 - i] != '#':
      ed = N - i
      break
  counts = {"#": 0, ".": 0}
  for i in range(st, ed):
    counts[S[i]] += 1

  print(min(counts["#"], counts["."]))

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

finded_black = False
answer1 = 0

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

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

finded_white = False
answer2 = 0

for c in reversed(s):
    if finded_white:
        if c == '.':
            continue
        else:
            answer2 += 1

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

print(min(answer1, answer2))

Submission status: Wrong Answer

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


it1=0
it2=N-1
it1f=False
it2f=False
r3=0

while it1<it2:
  if S[it1]!=".":
    if it1f==True and it2f==True:
      r3+=1
      it1+=1
      it1f=False
    else:
      it1f=True
  else:
    it1+=1

  if S[it2]!="#":
    if it1f==True and it2f==True:
      r3+=1
      it2-=1
      it2f=False
    else:
      it2f=True
  else:
    it2-=1

print(r3)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
while True:
    if len(s) == 0 or s[0] != ".":
        break
    if s[0] == ".":
        s.pop(0)
    else:
        break
while True:
    if len(s) == 0 or s[-1] != "#":
        break
    if s[-1] == "#":
        s.pop(-1)
    else:
        break

a = s.count("#")
b = s.count(".")
print(min(a,b))

Submission status: Wrong Answer

Solution code:
import copy

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s = "#"
i = 0
while s == "#":
#	print(s,i)
	i += 1
	if i == N:
		break
	s = S[i]
c = 0
t = i
while i < N:
	if S[i] == "#":
		c += 1
	i += 1
print(min(c,(N-t)-c))

Submission status: Wrong Answer

Solution code:
# # == black
# . == white
#黒い石のすぐ右に白い石があるような箇所がないようにしたい
b = input()
a = list(str(input()))
counter = 0
for i in range(0,len(a)-1):
    if a[i] == "#":
        if a[i] != a[i+1]:
            counter += 1
        else:
            pass
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count=0
if S.count(".")>S.count("#"):
    for i in range(n):
        if S[n-1]==".":
            if S[n-1-i]=="#":
                count+=1
        else:
            if S[n-1-i]==".":
                for j in range(n-i):
                    if S[n-i-1-j]=="#":
                        count+=1
                        
else:
    for k in range(n):
        if S[n-1]==".":
            if S[n-1-k]==".":
                count+=1
        else:
            if S[n-1-k]=="#":
                for l in range(n-k):
                    if S[n-k-1-l]==".":
                        count+=1
                        
print(count)

Submission status: Wrong Answer

Solution code:

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

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 = 0
for i in range(N):
    if S[i] == '#':
        c2 = i
        break
a = S[:c1 + 1].count(".")
b = S[:c1 + 1].count("#")
cc = S[c2+1:].count("#")
d = S[c2+1:].count(".")
ans = min(a, b, cc, d)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
LS = list(S)
a = '##.#'
b = '##..'
c = '.#.#'
d = '.#..'
ans = 0
if N == 1:
    print(0)
elif N == 2:
    if S == '#.':
        print(1)
    else:
        print(0)
elif N == 3:
    if S.find('#.') != -1:
        print(1)
    else:
        print(0)
else:
    S = '.' + S
    S = S + '#'
    t = S[:4]
    e = 3
    N += 2
    while True:
        if t == a:
            ans += 1
            LS[e-1]  == '#'
        elif t == b:
            ans += 1
            LS[e-1]  == '#'
        elif t == c:
            ans += 1
            LS[e-1] == '#'
        elif t == d:
            ans += 1
            LS[e-2] = '.'
        e += 1
        if e >= N-1:
            break
        t = t[1:] + S[e+1]
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
A = []
B = []
for i in range(N):
    if S[i] == "#":
        A.append(i)
for i in range(N):
    if S[i] == ".":
        B.append(i)

try:
    ans1 = N-min(A)-len(A)
except:
    ans1 = 0
try:
    ans2 = N-max(A)+max(B)-len(B)
except:
    ans2 = 0
print(min(ans1,ans2))