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:
# TLEkuraisou 

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

cnt=0
for i in range(n):
    a=s.count(".#")
    if a==0:
        break
    cnt+=a
    s=s.replace(".#","..")
    
print(s,cnt)

Submission status: Wrong Answer

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

black_right, min_val = 0, 2000001
white_left = s.count('.')
ans = []

for moji in s:
    if moji == '.':
        white_left -=1
    else:
        black_right += 1
    ans.append(white_left+black_right)
    #min_val = min(min_val, white_left+black_right)

print(min(ans))

Submission status: Wrong Answer

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

black_right, min_val = 0, 2000001
white_left = s.count('.')

for moji in s:
    if moji == '.':
        white_left -=1
    else:
        black_right += 1
    min_val = min(min_val, white_left+black_right)

print(min_val)

Submission status: Wrong Answer

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

black_right, min_val = 0, 200001
white_left = s.count('.')

for i in range(len(s)):
    if s[i] == '#':
        black_right += 1
    else:
        white_left -=1 if white_left > 0 else 0
    min_val = min(min_val, white_left+black_right)

print(min_val)

Submission status: Wrong Answer

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

black_right, min_val = 0, 200001
white_left = s.count('.')

for i in range(len(s)):
    if s[i] == '#':
        black_right += 1
    else:
        white_left -=1
    min_val = min(min_val, white_left+black_right)

print(min_val)

Submission status: Wrong Answer

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

black = 0
min_val = 200001
tot_white = s.count('.')

for i in range(len(s)):
    if s[i] == '#':
        black += 1
    else:
        tot_white -=1
    print(tot_white, black)
    min_val = min(min_val, tot_white+black)

print(min_val)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
s = np.array([1 if i == '#' else 0 for i in input()])
black = np.count_nonzero(s)

print(min(black,n-black))

Submission status: Wrong Answer

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

black = s.count("#") 
white = s.count(".")

if black == 0 or white == 0:
    ans = 0
else:
    ans = min(black-s[::-1].index("."),white-s.index("#"))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=0
c=0   # まだ白だけな状態
for i in range(n):
  if s[i]=="." and c==0:
    continue
  elif s[i]=="." and c==1:
    ans += 1
  elif s[i]=="#" and c==0:
    c=1
  else:
    continue
print(ans)

Submission status: Wrong Answer

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

cumdots = [0] * (N+1)

for i in range(N):
  cumdots[i+1] = cumdots[i] + (1 if S[i]=="." else 0)
  
print(cumdots)

hands = N+1
for i in range(N):
  #i番目までをdot, i+1番目からsharpとする
  leftops = i - cumdots[i]
  rightops = cumdots[N] - cumdots[i+1]
  hands = min(hands, leftops + rightops)
  
print(hands)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
S = list(str(input()))

Sw = copy.deepcopy(S)
Sb = copy.deepcopy(S)

w = 0
b = 0

for i in range(N-1) :
  if Sw[N-i-2] == "#" and Sw[N-i-1] == "." :
    w += 1
    Sw[N-i-2] = "."
  if Sb[i] == "#" and Sb[i+1] == "." :
    b += 1
    Sb[i+1] = "#"
    
print (min(b, w))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
S = list(str(input()))

Sw = copy.deepcopy(S)
Sb = copy.deepcopy(S)

w = 0
b = 0

for i in range(N-1) :
  if Sw[i] == "#" and Sw[i+1] == "." :
    w += 1
    Sw[i] = "."
  if Sb[i] == "#" and Sb[i+1] == "." :
    b += 1
    Sw[i+1] = "#"
    
print (min(b, w))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
S = list(str(input()))

Sw = copy.deepcopy(S)
Sb = copy.deepcopy(S)

w = 0
b = 0

for i in range(N-1) :
  if Sb[i] == "#" and Sb[i+1] == "." :
    b += 1
    Sb[i+1] = "#"
  if Sw[N-i-1] == "." and Sw[N-i-2] == "#" :
    w += 1
    Sw[N-i-2] = "."
print (min(b, w))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
S = str(input())

w = 0
b = 0

for i in range(N-1) :
  if S[i] == "#" and S[i+1] == "." :
    b += 1
  if S[N-i-1] == "." and S[N-i-2] == "#" :
    w += 1
print (min(b, w))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
S = str(input())

f = False
w = 0
b = 0
for i in range(N) :
  if f == False :
    if S[i] != "." :
      f = True
  else :
    if S[i] == "." :
      w += 1
    else :
      b += 1
print (min(w, b))

Submission status: Wrong Answer

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

w = S.count(".")
bl = S.count("#")

cnt = 0
for i in S[::-1]:
    if i != "#":
        break
    cnt += 1
bl -= cnt
cnt = 0
for i in S:
    if i != ".":
        break
    cnt += 1
w -= cnt
print(min(w, bl))

Submission status: Wrong Answer

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

w = S.count(".")
bl = S.count("#")

cnt = 0
for i in S[::-1]:
    if i != "#":
        break
    cnt += 1
bl -= cnt
print(min(w, bl))

Submission status: Wrong Answer

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

w = S.count(".")
bl = S.count("#")

print(min(w, bl))

Submission status: Wrong Answer

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

right = 0
cond = 0
white, black = 0,0
for s in S[::-1]:
	if cond == 0:
		if s == '#':
			right += 1
		else:
			white += 1
			cond = 1

	else:
		if s == '#':
			black += 1
		else:
			white += 1

if cond == 0:
	print(0)
elif black == 0:
	print(0)
else:
	print(min(black,white))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
black = 0
white = 0
d = {}
for i in range(N):
  if S[i] == "#":
    black += 1
  elif S[i] == ".":
    white += 1
  if i == N-1:
    if S[i] == S[i-1]:
      d[i] = max(black, white)
    else:
      if S[i] == "#":
        d[i] = black
      else:
        d[i] = white
    break
  if S[i] == "#" and S[i+1] == ".":
    d[i] = black
    black = 0
  elif S[i] == "." and S[i+1] == "#":
    d[i] = white
    white = 0
d = sorted(d.items())
ans = 0
for i in range(len(d)-1):
  if S[d[i][0]] == "#" and S[d[i+1][0]] == ".": 
    ans += min(d[i][1], d[i+1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if s[-1]=="#":
  print(s.count("#")-1)
else:
  print(s.count("#"))

Submission status: Wrong Answer

Solution code:
n = int(input())
s=input()
if ('.' not in s) or ('#' not in s):
    print(0)
else:
    bc = [0 for i in range(n)]
    wc = [0 for i in range(n)]
    for i in range(n):
        if s[i] == '#':
            bc[i] =1
        else:
            wc[i] = 1
    for i in range(n-1):
        bc[i+1] += bc[i]
    for i in range(n-1,0,-1):
        wc[i-1] += wc[i]
    ans = n
    for i in range(n-1):
        ans = min(ans,bc[i]+wc[i+1])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s=input()
bc = [0 for i in range(n)]
wc = [0 for i in range(n)]
for i in range(n):
    if s[i] == '#':
        bc[i] =1
    else:
        wc[i] = 1
for i in range(n-1):
    bc[i+1] += bc[i]
for i in range(n-1,0,-1):
    wc[i-1] += wc[i]
bc.insert(0,0)
wc.insert(0,0)
bc.append(0)
wc.append(0)
ans = n
for i in range(n-1):
    ans = min(ans,bc[i]+wc[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s=input()
count = []
for i in range(n):
    former = s[:i]
    latter = s[i:]
    fc = former.count('#')
    lc = latter.count('.')
    count.append(fc+lc)
print(min(count))

Submission status: Wrong Answer

Solution code:
n = int(input())
s=input()
if '#' not in s:
    print(0)
else:
    firstb = s.index('#')
    s2 = s[firstb:]
    s2b = s2.count('#')
    s2w = len(s2)-s2b
    print(min(s2b,s2w))

Submission status: Wrong Answer

Solution code:
n = int(input())
s=input()
if '#' not in s:
    print(0)
else:
    firstb = s.index('#')
    s2 = s[firstb:]
    s2b = s2.count('#')
    s2w = n-s2b
    print(min(s2b,s2w))

Submission status: Wrong Answer

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

idx="none"
count=0
count2=0
flag=0
for i in range(N-1,-1,-1):
    if S[i]=="#":
        count2+=1
    if flag and S[i]=="#":
        count+=1

    elif S[i]==".":
        if not flag:
            idx=i
        flag=1

idx2=-1
for i in range(N):

    if S[i]==".":
        idx2=i
    else:
        break
if idx=="none":
    print(0)
else:
    #print(count,idx)
    print(min(count2,N-count2,count,idx+1-count,idx+1-count-(idx2+1)))

Submission status: Wrong Answer

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

idx="none"
count=0
flag=0
for i in range(N-1,-1,-1):
    if flag and S[i]=="#":
        count+=1

    elif S[i]==".":
        if not flag:
            idx=i
        flag=1

idx2=-1
for i in range(N):

    if S[i]==".":
        idx2=i
    else:
        break
if idx=="none":
    print(0)
else:
    #print(count,idx)
    print(min(count,idx+1-count,idx+1-count-(idx2+1)))

Submission status: Wrong Answer

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

idx="none"
count=0
flag=0
for i in range(N-1,-1,-1):
    if flag and S[i]=="#":
        count+=1

    elif S[i]==".":
        if not flag:
            idx=i
        flag=1
if idx=="none":
    print(0)
else:
    #print(count,idx)
    print(min(count,idx+1-count))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=[i for i in input()]
stp=0
for i in range(N-1,-1,-1):
    if S[i]=='.':
        flg=i
        break
    else:
        if i==0:
            stp=1
            flg=0
for i in range(N):
    if S[i]=='#':
        flg2=i
        break
    else:
        if i==N-1:
            stp=1
            flg2=0
ans1=S[:flg].count('#')
ans2=S[flg2:].count('.')
ans=min(ans1,ans2)
if stp==1:
    ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=[i for i in input()]
ans=0
for i in range(N-1):
    if S[i]=='#' and S[i+1]=='.':
        ans+=1
print(ans)

Submission status: Wrong Answer

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

b = 0
m = 0
for i in reversed(range(n)):
    if m == 0 and s[i]==".":
        m = 1
        continue
    
    if m == 1 and s[i]== "#":
        b +=1
ans = min(a,b)
print(ans)

Submission status: Wrong Answer

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

b = 0
flag = 0
for i in reversed(range(n)):
    if flag == 0 and s[i]==".":
        flag =1
    
    if flag == 1 and s[i]== "#":
        b +=1
ans = min(a,b)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
cnt=0
for i in range(N):
    if S[i]==".":
        cnt+=1
    else:
        break
print(S.count(".")-cnt)

Submission status: Wrong Answer

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

bl = [0]
wl = [0]
a = 0
b = 0
for s in sl:
   if s == "#":
      b += 1
   if s == ".":
      a += 1
   bl.append(a)
   wl.append(b)

ans = float("inf")
for i in range(n):
   print(wl[i+1], bl[-1] - bl[i+1])
   tmp = wl[i+1] + bl[-1] - bl[i+1]
   ans = min(ans, tmp)

ans = min(wl[-1],ans)
print(ans)

Submission status: Wrong Answer

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

bl = [0]
wl = [0]
a = 0
b = 0
for s in sl:
   if s == "#":
      b += 1
   if s == ".":
      a += 1
   bl.append(a)
   wl.append(b)

ans = float("inf")
for i in range(n):
   tmp = wl[i+1] + bl[-1] - bl[i+1]
   ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
sum_b = []
sum_w = []
b = 0
w = 0

for s in S:
    if s == "#":
        b += 1
    else:
        w += 1
    # 白黒の累積和作る
    sum_b.append(b)
    sum_w.append(w)

ans = float("inf")
for i in range(N):
    # i番目までにある黒をすべて白にし、それ以降の白をすべて黒にするのに必要な手数
    buf = sum_b[i] + (sum_w[-1] - sum_w[i])
    # 更新するか否か
    ans = min(ans, buf)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
sum_b = []
sum_w = []
b = 0
w = 0

for s in S:
    if s == "#":
        b += 1
    else:
        w += 1
    # 白黒の累積和作る
    sum_b.append(b)
    sum_w.append(w)

print(sum_b)
print(sum_w)

ans = float("inf")
for i in range(N):
    # i番目までにある黒をすべて白にし、それ以降の白をすべて黒にするのに必要な手数
    buf = sum_b[i] + (sum_w[-1] - sum_w[i])
    # 更新するか否か
    ans = min(ans, buf)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
S = input()
S_list = []

for s in S:
    S_list.append(s)

C = collections.Counter(S_list)

w_count = 0
for s in S:
    if s == ".":
        w_count += 1
    else:
        break

print(min(C["#"], C["."] - w_count))

Submission status: Wrong Answer

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

flag_b = False
count_b = 0
count_w = 0
ans = 0
buf = S[0]
S += "e" # 終了判定のため末尾に挿入

for s in S:
    if s == buf:
        if s == "#":
            count_b += 1
        else:
            count_w += 1
    else:
        if s == "#":
            ans += min(count_b, count_w)
            count_b = 1
            count_w = 0
        elif s == ".":
            count_w = 1
        else:
            ans += min(count_b, count_w)
    buf = s

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnts = []
cnt = 0
for i in range(N):
  if i == 0:
    prvs = S[i]
    cnt += 1
  else:
    if S[i]==prvs:
      cnt += 1
    else:
      cnts.append([prvs,cnt])
      prvs = S[i]
      cnt = 1
  if i == N-1:
    cnts.append([prvs,cnt])
if len(cnts) == 1:
  print(0)
else:
  cntw,cntb = 0,0
  for i in range(len(cnts)):
    if (i == 0 and cnts[i][0]=='.'):
      continue
    if cnts[i][0]=='.':
      cntw += cnts[i][1]
    elif cnts[i][0]=='#':
      cntb += cnts[i][1]
  print(min(cntw,cntb))
#print(cnts)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnts = []
cnt = 0
for i in range(N):
  if i == 0:
    prvs = S[i]
    cnt += 1
  else:
    if S[i]==prvs:
      cnt += 1
    else:
      cnts.append([prvs,cnt])
      prvs = S[i]
      cnt = 1
  if i == N-1:
    cnts.append([prvs,cnt])
if len(cnts) == 1:
  print(0)
else:
  cntw,cntb = 0,0
  for i in range(len(cnts)):
    if (i == 0 and cnts[i][0]=='.') or (i == len(cnts)-1 and cnts[i][0]=='#'):
      continue
    if cnts[i][0]=='.':
      cntw += cnts[i][1]
    elif cnts[i][0]=='#':
      cntb += cnts[i][1]
  print(min(cntw,cntb))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnts = []
cnt = 0
for i in range(N):
  if i == 0:
    prvs = S[i]
    cnt += 1
  else:
    if S[i]==prvs:
      cnt += 1
    else:
      cnts.append([prvs,cnt])
      prvs = S[i]
      cnt = 1
  if i == N-1:
    cnts.append([prvs,cnt])
if len(cnts) == 1:
  print(0)
else:
  cntw,cntb = 0,0
  for i in range(len(cnts)):
    if (i == 0 and cnts[i][0]=='.') or (i == N-1 and cnts[i][0]=='#'):
      continue
    if cnts[i][0]=='.':
      cntw += cnts[i][1]
    elif cnts[i][0]=='#':
      cntb += cnts[i][1]
  print(min(cntw,cntb))

Submission status: Wrong Answer

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

L=0
R=N-1
while L<=N-1 and S[L]=='.':
    L+=1
while R>=0 and S[R]=='#':
    R-=1
B=0
for i in range(L,R+1):
    if S[i]=='#':
        B+=1
D=max(R-L+1,0)
W=D-B
print(min(B,W))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
si = S.find('#')
num_w, num_b = -1, -1
if si != -1:
  num_w = S[si+1:].count('.')
  
ei = S.rfind('.')
if ei != -1:
  num_b = S[:ei].count('#')

print(max(min(num_w, num_b),0))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
si = S.find('#')
num_w, num_b = -1, -1
if si != -1:
  num_w = S[si:].count('.')
  
ei = S.rfind('.')
if ei != -1:
  num_b = S[:ei].count('#')

print(max(min(num_w, num_b),0))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
si = S.find('#')
num_w, num_b = -1, -1
if si != -1:
  num_w = S[si:].count('.')
  
ei = S.rfind('.')
if ei != -1:
  num_b = S[:ei].count('#')

print(max(min(num_w, N-si-num_w),0))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
si = S.find('#')
if si != -1:
  print(S[si:].count('.'))
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=[]
c=[]
b,w=0,0
for i in range(n):
    if s[i]=='#':
        b+=1
    else:
        w+=1
    a.append([b,w])
wa=a[-1][1]
for i in range(n):
    c.append(a[i][0]+wa-a[i][1])
print(min(min(c),abs(n-wa)))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ary = [0]
t = '.'
for s in S:
    if s == t:
        ary[-1] += 1
    else:
        ary.append(1)
        t = s
if t == '.':
    ary.append(0)
ans = 0
l = 1
r = len(ary)-2
while l < r:
    if ary[l] > ary[r]:
        ans += ary[r]
        r -= 1
    elif ary[l] == ary[r]:
        ans += ary[l]
        l += 1
        r -= 1
    else:
        ans += ary[l]
        l += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ary = [0]
t = '.'
for s in S:
    if s == t:
        ary[-1] += 1
    else:
        ary.append(1)
        t = s
if t == '.':
    ary.append(0)
w = 0
b = 0
for n in ary[2::2]:
    w += n
for n in ary[1:-1:2]:
    b += n
print(min(w, b))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ary = [0]
t = '.'
for s in S:
    if s == t:
        ary[-1] += 1
    else:
        ary.append(1)
        t = s
w = 0
b = 0
for n in ary[2::2]:
    w += n
for n in ary[1:-1:2]:
    b += n
print(min(w, b))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ary = [0]
t = '.'
for s in S:
    if s == t:
        ary[-1] += 1
    else:
        ary.append(1)
        t = s
w = 0
b = 0
for n in ary[::2]:
    w += n
for n in ary[1:-1:2]:
    b += n
if len(ary) % 2:
    b += ary[-1]
print(min(w, b))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ary = [0]
t = '.'
for s in S:
    if s == t:
        ary[-1] += 1
    else:
        ary.append(1)
        t = s
w = 0
b = 0
for n in ary[::2]:
    w += n
for n in ary[1:-1:2]:
    b += n
print(min(w, b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ind=S.find("#")
S2=S[ind:len(S)]

s=S2.count("#")
d=S2.count(".")

print(min(d,s))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

s = [1 if i == '#' else 0 for i in S]
a = list(accumulate(s))
b = list(reversed(list(accumulate(reversed(s)))))
answer = N
for i in range(1, N - 1):
    tmp = a[i] + N - i - 1 - b[i]
    if tmp < answer:
        answer = tmp

answer = min(answer, a[-1], N - a[-1])
print(answer)

Submission status: Wrong Answer

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

black = S.count('#')
here = 0
if S[0] == '.':
    for i in range(N - 1):
        if S[i] == '.' and S[i + 1] == '#':
            here = i + 1
            break

print(min(black, N - black, S[here:].count('.')))

Submission status: Wrong Answer

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

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

print(min(black, N - black, S[here:].count('.')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w_cnt = S.count('.')
b_cnt = 0
changes = [0]*N
for i in range(N):
    if S[i] == '.':
        w_cnt -= 1
        changes[i] = b_cnt + w_cnt
    else:
        b_cnt += 1
        changes[i] = b_cnt + w_cnt
#print(changes)
print(min(changes))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w_cnt = S.count('.')
b_cnt = 0
changes = [0]*N
for i in range(N):
    if S[i] == '.':
        changes[i] = b_cnt + w_cnt
        w_cnt -= 1
    else:
        changes[i] = b_cnt + w_cnt
        b_cnt += 1
#print(changes)
print(min(changes))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
S = input()
blacks = np.zeros(N)
whites = np.zeros(N)
b_cnt = 0
w_cnt = 0
for i in range(N):
    if S[i] == '#':
        b_cnt += 1
        blacks[i] = b_cnt
    else:
        blacks[i] = b_cnt
for i in range(N):
    if S[N-1-i] == '.':
        w_cnt += 1
        whites[N-1-i] = w_cnt
    else:
        whites[N-1-i] = w_cnt

changestones = blacks + whites
# print(blacks)
# print(whites)
# print(changestones)
print(min(np.min(changestones),w_cnt,b_cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
v = 0
w = 0
for i in range(N):
  if S[i] == '.':
    v = i
    w += 1
print(min(v+1-w, w))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
v = 0
w = 0
for i in range(N):
  if S[i] == '.':
    v = i
    w += 1
print(min(i+1-w, w))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
if '#' in s:
    if s[n-1]=='.':
      for i in range(s.index('#'),n):
        if s[i]=='#':
          cnt+=1
      if cnt>len(s[s.index('#'):])//2:
        print(len(s[s.index('#'):])-cnt)
      else:
        print(cnt)
    else:
      for i in range(s.index('#'),n-1):
        if s[i]=='#':
          cnt+=1
      if cnt>len(s[s.index('#'):n-1])//2:
        print(len(s[s.index('#'):n-1])-cnt)
      else:
        print(cnt)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
c = 0
while True:
  f = True
  for i in range(n-1):
    if s[i] == "#" and s[i+1] == ".":
      f = False
      s[i] = "."
      c += 1
  if f:
    break
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
rightWhite=S.rfind(".")
leftBlack=S.find("#")

ans=0
if rightWhite>=0:
  ans=S[:rightWhite].count("#")
if leftBlack>=0:
  ans=min(ans,S[leftBlack:].count("."))
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    w = s.count(".")
    b = 0
    mc = 10 ** 10
    for i in range(n):
        if s[i] == "#":
            b += 1
        else:
            w -= 1
        mc = min(mc, b + w)
    print(mc)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

right_black = S.count('#')
right_white = S.count('.')
left_black, left_white = 0, 0

ans = len(S)
for s in S:
    if s == '#':
        right_black -= 1
        left_black += 1
    else:
        right_white -= 1
        left_white += 1

    ans = min(ans, left_black + right_white)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = list(str(readline().rstrip().decode('utf-8')))
    if len(collections.Counter(s)) == 1:
        print(0)
    else:
        sc1 = s.count(".")
        sc2 = s.count("#")
        cnt = 0
        for i in range(1, n):
            if s[-i-1] == "#" and s[-i] == ".":
                cnt += 1
                s[-i-1] = "."
        print(min(cnt, sc1, sc2))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = list(str(readline().rstrip().decode('utf-8')))
    cnt1 = s.count(".")
    cnt2 = 0
    for i in range(1, n):
        if s[-i-1] == "#" and s[-i] == ".":
            cnt2 += 1
            s[-i-1] = "."
    print(min(cnt1, cnt2))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import re

N=int(input())
S=input()
print(len(re.findall('#.',S)))

Submission status: Wrong Answer

Solution code:
import re

N=int(input())
S=input()
print(len(re.findall('.#',S)))

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n=inp()
    s=input()
    key1 = 0
    key2 = 0
    cnt1 = 0
    cnt2 = 0
    cnt3 = 0
    cnt4 = 0
    for i in range(n):
        if s[i]=='.':
            key1 = 1
            if key2 == 1:
                cnt1 += 1
            cnt2 += cnt3
        else:
            key2 = 1
            if key1 == 0:
                cnt4 += 1
            if key1 == 1:
                cnt2 += cnt4
                cnt4 = 0
                cnt3 += 1
    print(min(cnt1,cnt2))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n=inp()
    s=input()
    key1 = 0
    key2 = 0
    cnt1 = 0
    cnt2 = 0
    cnt4 = 0
    for i in range(n):
        if s[i]=='.':
            key1 = 1
            if key2 == 1:
                cnt1 += 1
        else:
            key2 = 1
            if key1 == 0:
                cnt4 += 1
            if key1 == 1:
                cnt2 += cnt4
                cnt4 = 0
                cnt2 += 1
    print(min(cnt1,cnt2))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n=inp()
    s=input()
    key1 = 0
    key2 = 0
    cnt1 = 0
    cnt2 = 0
    for i in range(len(s)):
        if s[i]=='.':
            key1 = 1
            if key2 == 1:
                cnt1 += 1
        else:
            key2 = 1
            if key1 == 1:
                cnt2 += 1
    print(min(cnt1,cnt2))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cur = s[0]
count = 0
l = []
for i in range(n):
  if s[i] == cur:
    count += 1
  else:
    l.append([cur,count])
    cur,count = s[i],1
l.append([cur,count])
ans = 0
for i in range(len(l)):
  if i == len(l)-1:
    print(ans)
  elif l[i][0] == '.':
    continue
  else:
    ans += min(l[i][1],l[i+1][1])