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:
import collections

n = int(input())
s = list(input())
# 黒い石("#")のすぐ右に白い石(".")があるような箇所がないようにしたい
# つまり、...... or .......###  or ###### の形

# 全部同じ奴にするに変えるべき個数 num1
c = dict(collections.Counter(s))
#print(c)
try:
  cnt1 = min(c['#'],c['.'])
except KeyError:
  cnt1 = 0
#print(cnt1)

# 左側に....を寄せるために変えるべき個数
# 右から調べていって、"#."となっているところがあれば、"##"に変える。
# ↑このやり方だと、"#..#"みたいなタイプに対応できない
cnt2 = 0
stack = []
for i in range(n-1,0,-1):
  # もしかしたら "#..#" タイプかも・・・
  if s[i-1] == "." and s[i]=="#":
    stack.append(".")
  
  # "#..#" タイプで挟まれてる最中かも・・・
  if stack and s[i-1] == "." and s[i]==".":
    stack.append(".")
  
  # "#..#" タイプの挟み終わり
  if stack and s[i-1] == "#" and s[i]==".":
    cnt2 += len(stack)
    stack = []
    
print(min(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
import numpy as np
N = int(input())
s = groupby(list(input()))
table = []
for key,group in s:
  cnt = 0
  for id,_ in enumerate(group,1):
    cnt = id
  table.append([key,cnt])
#print(table)
if len(table) == 1:
  print(0)
  exit()
B = [0] * (len(table) + 1)
W = [0] * (len(table) + 1)
for i in range(len(table)):
  if table[i][0] == "#":
    B[i+1] += table[i][1]
  else:
    W[i+1] += table[i][1]
B = np.cumsum(np.array(B))
W = np.cumsum(np.array(W)) 
ans = float("inf")
for i in range(len(table)):
  ans = min(ans,B[i] + W[-1] - W[i])
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
import numpy as np
N = int(input())
s = groupby(list(input()))
table = []
for key,group in s:
  cnt = 0
  for id,_ in enumerate(group,1):
    cnt = id
  table.append([key,cnt])
#print(table)
if len(table) == 1:
  print(0)
  exit()
B = [0] * len(table)
W = [0] * len(table)
for i in range(len(table)):
  if table[i][0] == "#":
    B[i] += table[i][1]
  else:
    W[i] += table[i][1]
B = np.cumsum(np.array(B))
W = np.cumsum(np.array(W))
#print(B)
#print(W)
ans = float("inf")
for i in range(len(table)):
  ans = min(ans,B[i] + W[-1] - W[i])
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
s = groupby(list(input()))
table = []
for key,group in s:
  cnt = 0
  for id,_ in enumerate(group,1):
    cnt = id
  table.append([key,cnt])
#print(table)
if len(table) == 1:
  print(0)
  exit()
table = table[::-1]
B = 0
W = 0
for t in table:
  if t[0] == ".":
    W += t[1]
  else:
    B += t[1]
if table[-1][0] == ".":
  W -= table[-1][1]
print(min(B,W))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
s = groupby(list(input()))
table = []
for key,group in s:
  cnt = 0
  for id,_ in enumerate(group,1):
    cnt = id
  table.append([key,cnt])
#print(table)
if len(table) == 1:
  print(0)
  exit()
table = table[::-1]
if table[0][0] == "#":
  table = table[1:]
  if len(table) == 1:
    print(0)
    exit()
B = 0
W = 0
for t in table:
  if t[0] == ".":
    W += t[1]
  else:
    B += t[1]
if table[-1][0] == ".":
  W -= table[-1][1]
print(min(B,W))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
s = groupby(list(input()))
table = []
for key,group in s:
  cnt = 0
  for id,_ in enumerate(group,1):
    cnt = id
  table.append([key,cnt])
#print(table)
if len(table) == 1:
  print(0)
  exit()
if table[0][0] == ".":
  table = table[1:]
ans = 0
for t in table:
  if t[0] == ".":
    ans += t[1]
print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())

b = 0
w = 0
for i in range(len(S)):
    if(S[i]=="#"):
        b += 1
    else:
        w += 1
        
b_ = 0
min_ = min([w,b])
w_ = 0
for i in range(len(S)):
    if(S[i]=="#"):
        b_ += 1
    else:
        w_ += 1
    min_ = min([w-w_+b_,min_])
        

print(min_)

Submission status: Wrong Answer

Solution code:
S=list(input())

b = 0
w = 0
for i in range(len(S)):
    if(S[i]=="#"):
        b += 1
    else:
        w += 1
        
b_ = 0
min_ = min([w,b])
for i in range(len(S)):
    if(S[i]=="#"):
        b_ += 1
    #if(S[i]=="#" and S[i+1]=="."):
    w_ = w-(i+1-b_)
    min_ = min([w_+b_,min_])
    #print(i,w_+b_)
        
    
    
print(min_)

Submission status: Wrong Answer

Solution code:
S=list(input())

b = 0
w = 0
for i in range(len(S)):
    if(S[i]=="#"):
        b += 1
    else:
        w += 1
        
b_ = 0
min_ = min([len(S)+1,w,b])
for i in range(len(S)-1):
    if(S[i]=="#"):
        b_ += 1
    #if(S[i]=="#" and S[i+1]=="."):
    w_ = w-(i+1-b_)
    min_ = min([w_+b_,min_])
    #print(i,w_+b_)
        
    
    
print(min_)

Submission status: Wrong Answer

Solution code:
# #=黒 .=白　#.という状態はダメ

S=list(input())

b = 0
w = 0
for i in range(len(S)):
    if(S[i]=="#"):
        b += 1
    else:
        w += 1
        
b_ = 0
min_ = min([len(S)+1,w,b])
for i in range(len(S)-1):
    if(S[i]=="#"):
        b_ += 1
    if(S[i]=="#" and S[i+1]=="."):
        w_ = w-(i+1-b_)
        min_ = min([w_+b_,min_])
        
    
    
print(min_)

Submission status: Wrong Answer

Solution code:
S=list(input())

b = 0
w = 0
for i in range(len(S)):
    if(S[i]=="#"):
        b += 1
    else:
        w += 1
        
b_ = 0
min_ = min([len(S)+1,w,b])
for i in range(len(S)):
    if(S[i]=="#"):
        b_ += 1
        
    w_ = w-(i+1-b_) #右側にある白の数
    min_ = min([w_+b_,min_])
    
    
print(min_)

Submission status: Wrong Answer

Solution code:
S=list(input())

b = 0
w = 0
for i in range(len(S)):
    if(S[i]=="#"):
        b += 1
    else:
        w += 1
        
b_ = w
min_ = min([len(S)+1,w,b])
for i in range(len(S)):
    if(S[i]=="#"):
        b += 1
        
    w_ = w-(i+1-b) #右側にある白の数
    min_ = min([w_+b_,min_])
    
    
print(min_)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b = 0
w = 0
bl = []
wl = []
for i in range(n):
    if s[i]==".":
        w += 1
        if b:
            bl.append(b)
            b = 0
    else:
        b += 1
        if w:
            wl.append(w)
            w = 0
if b:
    bl.append(b)
if w:
    wl.append(w)
b_sum = 0
w_sum = 0
if s[-1] == "#":
    b_sum = sum(bl[:-1])
else:
    b_sum = sum(bl)
if s[0] == ".":
    w_sum = sum(wl[1:])
else:
    w_sum = sum(wl)

print(min(b_sum,w_sum))

Submission status: Wrong Answer

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

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

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

print(max(s[w:-1].count('.'), s[-1:-b:-1].count('#')))

Submission status: Wrong Answer

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

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

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

print(min(s[w:-1].count('.'), s[-1:-b:-1].count('#')))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
white_all = s.count(".")
black_all = s.count("#")
white = 0
black = 0
num = []

for i in range(n):
    if s[i] == ".":
        white += 1
    else:
        black += 1
    num.append(black + (white_all - white))

if white_all == n or black_all == n:
    print(0)
    exit()
print(min(num))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
white_all = s.count(".")
white = 0
black = 0
num = []

for i in range(n):
    if s[i] == ".":
        white += 1
    else:
        black += 1
    num.append(black + (white_all - white))
print(min(num))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
if s[0] == ".":
    cnt1 = -1
else:
    cnt1 = 0
if s[-1] == "#":
    cnt2 = -1
else:
    cnt2 = 0

for i in range(n):
    if s[i] == ".":
        cnt1 += 1
    else:
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
if s[0] == ".":
    cnt1 = -1
else:
    cnt1 = 0
cnt2 = 0

for i in range(n):
    if s[i] == ".":
        cnt1 += 1
    else:
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Wrong Answer

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


cnt1 = 0
cnt2 = 0

for i in range(n):
    if s[i] == ".":
        cnt1 += 1
    else:
        cnt2 += 1
print(min(cnt1, cnt2))

Submission status: Wrong Answer

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


cnt1 = 0
cnt2 = 0

for k in range(n - 4):
    if s[k] == "#" and s[k+1] == "." and s[k+2] == "#" and s[k+3] == "." and s[k+4] == "#":
        s[k+1] = "#"
        s[k+3] = "#"
        cnt1 += 2

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

print(cnt1 + cnt2)

# #が黒、.が白　#.と並ばなければおｋ

Submission status: Wrong Answer

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


cnt1 = 0
cnt2 = 0

for k in range(n - 4):
    if s[k] == "#" and s[k+1] == "." and s[k+2] == "#" and s[k+3] == "." and s[k+4] == "#":
        s[k+2] = "."
        cnt1 += 1

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

print(cnt1 + cnt2)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
S = input()

dq = deque()
for s in S:
    if not dq:
        dq.append(s)
    elif dq[-1] == "#" and s == ".":
        dq.pop()
        dq.append(s)
    else:
        dq.append(s)

ans = N - len(dq)
print(ans)

Submission status: Wrong Answer

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

b = 0

for i in range(N-1):
    if S[i] != S[i+1]:
        b += 1

ans = max(b-1, 0)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = 0
r = N-1

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

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

ans = N -(r - l + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
i=0
s=0
while i<N-1:
  if S[i]=='*':
    if S[i+1]=='.':
      s+=1
  i+=1
print(s)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())
s=list(input())
v=list(reversed(s))
ans=float('inf')
s1=[]

s=itertools.accumulate(s)
v=itertools.accumulate(v)
s=['']+list(s)
v=['']+list(v)

for i in range(n):
    cnt=s[i].count('#')+v[-(i+1)].count('.')
    ans=min(cnt,ans)
print(ans)

Submission status: Wrong Answer

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

cnt2=0
f=0
for i in range(n-1,-1,-1):
    if s[i]==".":
        f=1
    else:
        if f:
            cnt2+=1
print(min(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(input())
N=len(S)

turn=0
kuro=0
shiro=0
last=0

ans=0
for index,item in enumerate(S):
    if item==".":
        kuro+=1
        last=0
    else:
        shiro+=1
        last+=1
    if kuro>shiro:
        turn=index
        ans=shiro-kuro

print(min(ans+kuro,shiro-last))#乱暴スギィ

Submission status: Wrong Answer

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

turn=0
kuro=0
shiro=0

ans=0
for index,item in enumerate(S):
    if item==".":
        kuro+=1
    else:
        shiro+=1
    
    if kuro>shiro:
        turn=index
        ans=shiro-kuro

print(ans+kuro)

Submission status: Wrong Answer

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

flag=False
ans=0
for i in range(N):
    if flag:
        if S[i]==".":
            ans+=1
    else:
        if S[i]=="#":
            flag=True
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
for i in s[::-1]:
    if i=="#":
        s=s[:-1]
    else:
        break
if len(set(list(s)))<=1:
    print(0)
    exit()    
print(min(s[min(0,s.index("#")):].count("."),s.count("#")))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()+"#"
print(min(s[min(0,s.index("#")):].count("."),s[:-2].count("#")))

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

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

rind=N
for i in reversed(range(N)):
  if S[i]==".":
    rind=i
    break

print(min(S[ind+1:].count("."),S[:rind].count("#")))

Submission status: Wrong Answer

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

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

print(S[i+1:].count("."))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=inf

  s=S()

  ans=min(ans,len(s)-s.count('.'))
  ans=min(ans,len(s)-s.count('#'))

  a=s.count('.')
  b=s.count('#')

  _a=0
  for i in range(n):
    if s[i]=='.':
      pass
    else:
      _a+=1
      a-=1
    ans=min(ans,_a+a)
  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=inf

  s=S()

  ans=min(ans,len(s)-s.count('.'))
  ans=min(ans,len(s)-s.count('#'))

  a=s.count('.')
  b=s.count('#')

  _a=0
  for i in range(n):
    if s[i]=='.':
      pass
    else:
      _a+=1
      b-=1
    ans=min(ans,_a+b)
  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
answer1=0
countB=0
countW=0
flag=True
for i in range(len(s)):
    if s[i]=="#":
        countB+=1
        flag=False
        continue
    if s[i]=="." and flag:
        countW+=1
        continue
    if s[i]=="." and  not flag:
        countW+=1
        answer1+=1
        continue
    if s[i]=="#" and  not flag:
        countB+=1
        continue


print(min(answer1,countB,countW))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
answer1=0
flag=True
for i in range(len(s)):
    if s[i]=="#":
        flag=False
    if s[i]=="." and   flag:
        continue
    if s[i]=="." and  not flag:
        answer1+=1
    if s[i]=="#" and  not flag:
        continue

print(answer1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=s.count(".")
ans=10**10
for i in s:
  if i==".":cnt -=1
  else:cnt +=1
  ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

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

cnt=0
for s in S:
  if s!="#":
    cnt+=1
ans=cnt

for s in S:
  if s==".":
    cnt-=1
  else:
    cnt+=1
ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
b,w=0,0
for i in s:
  if i=="#":b +=1
  else:w +=1
print(min(b,w))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt,i=0,0
while i<n-1:
    if s[i]=="#" and s[i+1]==".":
        cnt +=1
        i +=2
        continue
    i +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
b,w=0,0
for i in s:
    if i=="#":b +=1
    else:w +=1

print(min(b,w)-1 if s[-1]=="#" and w>b else min(b,w))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
b,w=0,0
for i in s:
    if i=="#":b +=1
    else:w +=1

print(min(b,w)-1 if s[-1]=="#" else min(b,w))

Submission status: Wrong Answer

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


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

ans = N
for i in range(N):
    tmp = (black[N-i]-black[0])+(i-(black[N]-black[N-i]))
    ans = min(tmp, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()
t=[len(list(v)) for k,v in groupby(s)]
r=s.count("#")
ans=[r]
l=0
if s[0]=="#":
    r-=t[0]
    ans.append(r)
    for i in range(2,len(t),2):
        l+=t[i-1]
        r-=t[i]
        ans.append(l+r)
else:
    for i in range(1,len(t),2):
        l+=t[i-1]
        r-=t[i]
        ans.append(l+r)
#print(ans)
print(min(ans))

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()
t=[len(list(v)) for k,v in groupby(s)]
r=s.count("#")
ans=[r]
l=0
if s[0]=="#":
    r-=t[0]
    for i in range(2,len(t),2):
        l+=t[i-1]
        r-=t[i]
        ans.append(l+r)
else:
    for i in range(1,len(t),2):
        l+=t[i-1]
        r-=t[i]
        ans.append(l+r)
#print(ans)
print(min(ans))

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()
t=[len(list(v)) for k,v in groupby(s)]
r=s.count("#")
ans=[r]
l=0
if s[0]=="#":
    for i in range(2,len(t),2):
        l+=t[i-1]
        r-=t[i]
        ans.append(l+r)
else:
    for i in range(1,len(t),2):
        l+=t[i-1]
        r-=t[i]
        ans.append(l+r)
print(min(ans))

Submission status: Wrong Answer

Solution code:
from numpy import*
from itertools import*
n=int(input())
s=input()
t=[len(list(v)) for k,v in groupby(s)]
#print(s)


if s[0]=="#":
    n=list(accumulate(t[i]for i in range(0,len(t),2)))
    m=list(accumulate(t[i]for i in range(1,len(t),2)))[::-1]
    if len(n)!=len(m):
        print(min(array([0]+n)+array(m+[0]*2)))
    else:
        print(min(array([0]+n)+array(m+[0])))
else:
    n=list(accumulate(t[i]for i in range(1,len(t),2)))
    m=list(accumulate(t[i]for i in range(0,len(t),2)))[::-1]
    if len(n)!=len(m):
        print(min(array([0]*2+n)+array(m+[0])))
    else:
        print(min(array([0]+n)+array(m+[0])))

Submission status: Wrong Answer

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

ans=0
for i in range(1,N-1):
    if S[i]=='#':

        if S[i+1]=='.':
            ans+=1
            S[i+1]='#'

    else:

        if S[i-1]=='#':
            ans+=1

print(ans)

Submission status: Wrong Answer

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

ans=0
k=0
s=0
for i in range(len(S)):
    if S[i]=='#':
        k+=1

        if i==len(S)-1:
            break

    if S[i]=='.' and ('#' in S[:S.index('.')]):
        s+=1

        if i==len(S)-1:
            ans+=min(s,k)
            k=0
            s=0
            break

        if i+1=='#':
            ans+=min(s,k)
            k=0
            s=0
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input().strip())

lb, lw, rb, rw = 0, 0, l.count("#"), l.count(".")


ans = lb+rw
for i in range(len(l)):
    if l[i] == "#":
        lb += 1
        rb -= 1
    else:
        lw += 1
        rw += 1

    ans = min(ans, lb+rw)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input().strip())

ans = 1000000000000
for i in range(1, len(l)):
    b1 = 0
    b2 = 0
    w1 = 0
    w2 = 0
    for j in range(i):
        if l[j] == "#":
            b1 += 1
        else:
            w1 += 1
    for j in range(i, len(l)):
        if l[j] == ".":
            w2 += 1
        else:
            b2 += 1

    ans = min(ans, b1+b2, w1+w2, b1+w2)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input().strip())

ans = 0
for i in range(len(l) - 1, 0, -1):
    if l[i] == "." and l[i - 1] == "#":
        l[i-1] = "."
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input().strip())

ans = 0
for i in range(len(l) - 1, 0, -1):
    if l[i] == "." and l[i - 1] == "#":
        ans += 1

print(ans)

Submission status: Wrong Answer

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

a = 0
b = 0
for i in range(n):
    if s[i] == '#':
        a = i
        break
c1 = 0
for i in range(a,n):
    if s[i] == '.':
        c1 += 1

c2 = 0
for i in range(n):
    if s[i] == '.':
        b = i
for i in range(0, b+1):
    if s[i] == '#':
        c2 += 1

ans = min(c1, c2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
s.append('#')
f1 = True
f2 = True
c1 = 0
c2 = 0
tmp1 = 0
tmp2 = 0
ans = 0

for i in range(n+1):
    if s[i] == '#':
        c1 += 1
        if f1:
            f1 = False
            f2 = True
            tmp2 = c2
            c2 = 0
            ans += min(tmp1, tmp2)


    if s[i] == '.':
        c2 += 1
        if f2:
            f2 = False
            f1 = True
            tmp1 = c1
            c1 = 0


print(ans)

Submission status: Wrong Answer

Solution code:
n= int(input())
s=input()
ans=0
kirby=0
for i in s:
  if kirby ==1 and i=='.':
    ans+=1
  if i =='#':
    kirby = 1
  else :
    kirby=0
print(ans)

Submission status: Wrong Answer

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

flag = True
if len(set(s)) == 1:
    flag = False
    print(0)

if flag:
    a = s.index('#')
    b = 0
    for i in range(n):
        if s[i] == '.':
            b = i
    #print(a, b)

    c = 0
    d = 0

    for i in range(a, n):
        if s[i] == '.':
            c += 1
    for i in range(0, b+1):
        if s[i] == '#':
            d += 1
    print(min(c,d))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import re

n = input()
string = input()

pattern = re.compile(r'#.')
res = re.findall(pattern, string)
print(len(res))

Submission status: Wrong Answer

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

l=[]

aa=s.rfind('.')
i=aa
bb=s.find('.')
c=s[:aa+1].count('.')
d=s[:aa+1].count('#')
ans=min(c,d)
while i>=0:
    a=s[:i].rfind('.')
    c-=1
    d-=i-a-1
    #print((c,d))
    ans=min(ans,(i-a+min(c,d)))
    #print(ans,a)
    i=a
    if a==bb:
        break

print(ans)

Submission status: Wrong Answer

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

l=[]

aa=s.rfind('.')
i=aa
bb=s.find('.')
c=s[:aa+1].count('.')
d=s[:aa+1].count('#')
ans=min(c,d)
while i>=0:
    a=s[:i].rfind('.')
    c-=1
    d-=i-a-1
    #print((c,d))
    ans=min(ans,(1+min(c,d)))
    #print(ans,a)
    i=a
    if a==bb:
        break

print(ans)

Submission status: Wrong Answer

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

ans=0
a=s.find('#');b=s.rfind('.')
#print(a,b)
if a<b:
    c=s[a:b+1].count('#');d=s[a:b+1].count('.')
    print(min(c,d))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=str(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:
def resolve():
    n = int(input())
    s = input()
    b_left, w_right = 0, s.count(".")
    ans = n
    for c in s:
        if c == "#":
            b_left += 1
        else:
            w_right -= 1
        if b_left + w_right < ans:
            ans = b_left + w_right
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    s = input()
    if len(set(s)) == 1:
        print(0)
    else:
        acc_w, acc_b = [], []
        w, b = 0, 0
        for i in range(n):
            if s[i] == ".":
                w += 1
            else:
                b += 1
            acc_w.append(w)
            acc_b.append(b)
        ans = min(s.count("."), s.count("#"))
        for i in range(n - 1):
            if s[i] == "." and s[i + 1] == "#":
                t = acc_b[i + 1] + acc_w[n - 1] - acc_w[i]
                if t < ans:
                    ans = t
        print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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


for i in range(N):

    if S[i] == '#':

        S=S[i:]

        break



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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
count = 0
for i in range(N):
    try:
        if S[i] =='#':

            if S[i+1] == '.':

                S[i+1] = '#'

                count += 1
                
    except IndexError:
        break

print(count)

Submission status: Wrong Answer

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

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

            if S[i+1] == '.':

                S[i+1] = 'X'

    except IndexError:
        break



print(S.count('X'))

Submission status: Wrong Answer

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

if S.count('.') < S.count('#'):
    print(S.count('.'))

elif S.count('.') == 0 or S.count('#') == 0:
    print(0)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s,b=input(),0
for i in range(n-1):
    if s[i]!=s[i+1]:
        b+=1
if s[0]==s[-1]:
    print(b//2)
else:
    print(b//2+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(input())
cnt = [0]*N

for i,stone in enumerate(arr):
  black = arr[:i].count('#')
  white = arr[i:].count('.')
  cnt[i] = white + black
print(min(cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(input())
cnt = []

for i,stone in enumerate(arr):
  black = arr[:i].count('#')
  white = arr[i:].count('.')
  cnt.append(white + black)
print(min(cnt))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

S =[]
for i in s:
    S.append(i)

w = 0
b = 0
an = n

for i in range(n-1,-1,-1):
    if i == "#":
        b += 1
    elif i == ".":
        w += 1

    if w > b:
        an = n-i

print(S)
print(i)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
i = S.find("#")
if i < 0:
  i = N
r = S[i:].count(".")
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

white=s.count(".")
black=0
ans=1145141919

for s_i in s:
    if s_i == "#":
        black+=1
    else:
        white-=1
    ans = min(ans, white+black)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
n=int(input())
s=input()

cnt_left=[]
cnt_right=[]
ans=1145141919
for i in range(1,n+1):
    cnt_right.append(s[:i].count("#"))
    cnt_left.append(s[i:].count("."))
for i in range(n):
    ans=min(ans,(cnt_right[i]+cnt_left[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
def main():

    N = int(input())
    S = input()
    search = False
    count = 0
    for i in range(N):
        if S[i] == "#" and not search:
            search = True
        if S[i] == "." and search:
            count += 1
    return count

if __name__ == '__main__':
    print(main())

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 = input()
cnt = 0
i = 0
while i < N:
    if(S[i] == '#'):
        i += 1
        while (i < N and S[i] == '.'):
            cnt += 1
            i += 1
            #print(i)
    else:
        i += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    S = input().rstrip()

    # すべてを白/黒にするコスト
    ans = min(S.count('.'), S.count('#'))

    white = [0] * (N + 1)

    for i, s in enumerate(S, start=1):
        white[i] += white[i - 1]
        if s == '.':
            white[i] += 1

    for mid, s in enumerate(S):
        # 左をすべて白にする
        left = (mid + 1 - white[mid])

        # 右をすべて黒にする
        right = white[N] - white[mid]

        ans = min(ans, left + right)

    print(ans)

sol()