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 sys
input=sys.stdin.readline
N=int(input())
S=input()
c=N
for i in range(N):
  b=0;w=0
  for j in range(N):
    if (i>=j) and S[j]=='#':
      b+=1
    elif (i<j) and S[j]=='.':
      w+=1
  c=min(c,b+w)
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

arr = [0] if S[0] == "." else []
count = 0
for i in range(len(S)):
  count += 1
  if S[i:i+2] == "#.":
    arr.append(count)
    count = 0  
  if S[i:i+2] == ".#":
    arr.append(count)
    count = 0
if S[-1] == ".":
  arr.append(count)
#print(arr)

result = sum([min(arr[i:i+2]) for i in range(0, len(arr), 2)])
print(result)

Submission status: Wrong Answer

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

arr = [0] if S[0] == "." else []
count = 0
for i in range(len(S)):
  count += 1
  if S[i:i+2] == "#.":
    arr.append(count)
    count = 0  
  if S[i:i+2] == ".#":
    arr.append(count)
    count = 0
arr.append(count)
#print(arr)

result = sum([min(arr[i:i+2]) for i in range(0, len(arr)-1, 2)])
print(result)

Submission status: Wrong Answer

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

black = s.count('#')
if black == 0 or black == n:
    print(0)
else:
    for i in range(n):
        if s[i]=='#':
            bloc = i
            break
    
    ans = min(black, n-black-bloc)
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()[:-1]
c=N*2
for i in range(N+1):
  c = min(c,S[:i].count('#')+S[i:].count("."))
print(c)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()
 
wh = 0
br = 0

for i in range(a):
  if(b[i] == '.'):
    wh += 1
    
tmp = a

if(wh != 0):
  for i in range(a):
    if(b[i] == '#'):
      br += 1
    else:
      wh -= 1
    if(tmp > br + wh):
      tmp = br + wh
else:
  tmp = 0
print(tmp)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()
 
wh = 0
br = 0

for i in range(a):
  if(b[i] == '.'):
    wh += 1
    
tmp = a

if(wh != 0):
  for i in range(a):
    if(b[i] == '#'):
      br += 1
    else:
      wh -= 1
    if(tmp >= br + wh):
      tmp = br + wh
else:
  tmp = 0
print(tmp)

Submission status: Wrong Answer

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

count_blk = []
count_wht = []

ct_blk = 0
ct_wht = 0
for i in S:
    if i == '#':
        ct_blk += 1
    else:
        ct_wht += 1
    count_blk.append(ct_blk)
    count_wht.append(ct_wht)

ans = 10**6
for i in range(N):
    ans = min(ans, count_blk[i] + ct_wht - count_wht[i])

print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()
 
wh = 0
br = 0

for i in range(a):
  if(b[i] == '.'):
    wh += 1
    
tmp = a

for i in range(a):
  if(b[i] == '#'):
    br += 1
  else:
    wh -= 1
  if(tmp >= br + wh):
    tmp = br + wh
print(tmp)

Submission status: Wrong Answer

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

print(sum([1 for i in range(len(S)-1) if S[i:i+2] == "#."]))

Submission status: Wrong Answer

Solution code:
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def prob():
    d = Debug()
    d.off()
    N = getInt()
    S = input()
    d.dmp((N, S),'N, S')
    count = 0
    i = 0
    while i < N and S[i] != '#':
        i += 1
    while i < N:
        if S[i] == '.':
            count += 1
        i += 1
        
    return count

ans = prob()
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
isBlack = 0
isWhite = 0
cwhite = 0
cblack = 0


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

j = n - 1
while j >= 0:
  if s[j] == ".":
    isWhite = 1
  if s[j] == "#" and isWhite == 1:
    cblack += 1
  j -= 1
print(min(cblack, cwhite))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
isBlack = 0
cwhite = 0
cblack = 0


for i in range(n):
  if s[i] == "#":
    isBlack = 1
    cblack += 1
  if s[i] == "." and isBlack == 1:
    cwhite += 1
print(min(cblack, cwhite))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
black = 0
count = 0

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

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=_I()
S=input()
#print(S)
for sidx in range(N):
	#print("a",sidx)

	if S[sidx]=="#":
		S=S[sidx:]
		break
if len(S)==0:
	print(0)
	exit()

#print(S)
S=S[::-1]
for sidx in range(len(S)):
	if S[sidx]==".":
		S=S[sidx:]
		break
if len(S)==0:
	print(0)
	exit()

#print(S)
cd=S.count(".")
cs=S.count("#")

#print(cd,cs)
ans=min(cd,cs)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
#print(S)
ans_list = [N]
for i in range(N):
        ans = 0
        for j in range(i+1):
                if S[j] == "#":
                        ans += 1
                        if ans > ans_list[i]:
                                break
        for t in range(i+1, N):
                if S[t] == ".":
                        ans += 1
                        if ans > ans_list[i]:
                                break
        ans_list.append(ans)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = str(input())

c = []

for i in range(len(b)):
    c.append(b[:i].count('#') + b[i:].count('.'))

print(min(c))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
intLength = int(input())
strStones = input()
intCount = 0
strPre = ""
aryBlack = re.findall("#", strStones)
if len(aryBlack) > intLength / 2:
    strBase = "#"
    strChange = "."
    for intIdx in range(intLength):
        if strPre == strBase and strStones[intIdx] == strChange:
            intCount += 1
            strPre = strBase
        else:
            strPre = strStones[intIdx]
else:
    strBase = "."
    strChange = "#"
    for intIdx in reversed(range(intLength)):
        if strPre == strBase and strStones[intIdx] == strChange:
            intCount += 1
            strPre = strBase
        else:
            strPre = strStones[intIdx]

print(intCount)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=_I()
S=input()
#print(S)
for sidx in range(N):
	#print("a",sidx)

	if S[sidx]=="#":
		S=S[sidx:]
		break
#print(S)
S=S[::-1]
for sidx in range(len(S)):
	if S[sidx]==".":
		S=S[sidx:]
		break
#print(S)
cd=S.count(".")
cs=S.count("#")

#print(cd,cs)
ans=min(cd,cs)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
#print(S)
ans_list = []
for i in range(N):
        ans = 0
        for j in range(i+1):
                if S[j] == "#":
                        ans += 1
        for t in range(i+1, N):
                if S[t] == ".":
                        ans += 1
        ans_list.append(ans)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
t=0
if s[0]==".":
  while t<=2:
    t=t
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
n=len(s)
li=[]
if s[0]=='.':
  a=0
  s.insert(0,"あ")
  for i in range (1,n+1):
    if s[i]==s[i-1]:
      a=a+1
    else:
      li.append(a)
      a=1
  li.append(a)
else:
  a=1
  for i in range (0,n-1):
    if s[i+1]==s[i]:
      a=a+1
    else:
      li.append(a)
      a=1
  if s[n-2]==s[n-1]:
    a=a+1
    li.append(a)
  else:
    li.append(a)
if s[0]=="あ":
  s.pop(0)
if s[n-1]==".":
  li.append(0)
len_li=len(li)
import math
t=math.floor(len_li/2)+1
l=[]
m=0
for j in range (0,t-1):
  m=m+li[2*j+1]
x=0
y=0
for k in range (0,t):
  l.append(m+y-x)
  y=y+li[2*k]
  if k!=t-1:
    x=x+li[2*k+1]
l.sort()
print(l[0])

Submission status: Wrong Answer

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

# count '#'
count_b = []
count = 0
for i in range(n):
    if s[i] == '#':
        count += 1
    count_b.append(count)

count_w = []
count = 0
for i in range(n-1, -1, -1):
    if i == n-1:
        pass
    elif s[i+1] == '.':
        count += 1
    count_w.insert(0, count)

total = [b + w for b, w in zip(count_b, count_w)]

print(min(total))

Submission status: Wrong Answer

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

# count '#'
count_b = []
count = 0
for i in range(n):
    if s[i] == '#':
        count += 1
    count_b.append(count)

count_w = []
count = 0
for i in range(n-1, -1, -1):
    if i == n-1:
        count_w.insert(0, 0)
    elif s[i+1] == '.':
        count += 1
    count_w.insert(0, count)

total = [b + w for b, w in zip(count_b, count_w)]

print(min(total))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re

intLength = int(input())
strStones = input()

intCount = 0
strPre = ""

aryBlack = re.findall("#", strStones)
if len(aryBlack) > intLength / 2:
    strBase = "#"
    strChange = "."
else:
    strBase = "."
    strChange = "#"

for intIdx in range(intLength):
    if strPre == strBase and strStones[intIdx] == strChange:
        intCount += 1
        strPre = strBase
    else:
        strPre = strStones[intIdx]

print(intCount)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
bs = 0
ws = s.count('.')
ans = n
for c in s:
    if c == '.':
        ws -= 1
    else:
        bs += 1
    now = ws + bs
    if ans > now:
        ans = now
print(ans)

Submission status: Wrong Answer

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

counterMin = 1000000
for b in range(N):
    counter=0
    for i in range(0, b):
        if S[i]=='#':
            counter+=1
    for i in range(b, N):
        if S[i]=='.':
            counter+=1
    if counter<counterMin:
        counterMin=counter
print(counterMin)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
intLength = int(input())
strStones = input()

intCount = 0
strPre = ""
for intIdx in range(intLength):
    if strPre == "#" and strStones[intIdx] == ".":
        intCount += 1
        strPre = "#"
    else:
        strPre = strStones[intIdx]

print(intCount)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
b = [0]*(n)
w = [0]*(n)
if n == 1:
    print(0)
    exit()
if s[0] ==".":
    w[0] =1
else:
    b[0] =1

for i in range(1,n):
    if s[i] == ".":
        w[i] = w[i-1] + 1
        b[i] =b[i-1]
    else:
        b[i] = b[i-1] + 1
        w[i] = w[i-1]
ans = n
for j in range(n):
    ans = min(ans,b[j]+w[-1]-w[j])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
b = [0]*(n)
w = [0]*(n)
if n == 1:
    print(0)
    exit()
if s[0] ==".":
    w[0] =1
else:
    b[0] =1
for i in range(1,n):
    if s[i] == ".":
        w[i] = w[i-1] + 1
        b[i] =b[i-1]
    else:
        b[i] = b[i-1] + 1
        w[i] = w[i-1]
ans = n
for j in range(n):
    ans = min(ans,b[j]+w[n-1]-w[j])
print(ans)

Submission status: Wrong Answer

Solution code:
# TPBC201C - Stones
n = int(input())
s1 = list(input())
s2 = s1
count_1 = 0
count_2 = 0

for i in range(n - 1):
    if s1[i] == '#' and s1[i + 1] == '.':
        s1[i + 1] = '#'
        count_1 += 1
        
for i in range(1, n):
    if s2[i] == '.' and s2[i - 1] == '#':
        s2[i - 1] = '.'
        count_2 += 1
        
print(min(count_1, count_2))

Submission status: Wrong Answer

Solution code:
# TPBC201C - Stones
n = int(input())
s = list(input())
count = 0

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

Submission status: Wrong Answer

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

flag = False
countA = 0
countB = 0
T = []
for i in range(N):
  if S[i] == '#':
    for j in range(N):
      if j >= i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countA = countA + 1
    break
T = []
for i in reversed(range(N)):
  if S[i] == '.':
    for j in range(N):
      if j > i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countB = countB + 1
    break

if countA < countB and countA != 0:
  print(countA)
else:
  print(countB)

Submission status: Wrong Answer

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#S=input()
#import fractions
#lis=list(map(int,input().split()))

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

flag=-1
count=0
for i in range(n):
    if s[i]=="#":
        count+=1
        if flag==-1:
            flag=i
btw=count
wtb=n-count-flag
ans=min(btw,wtb)
if count==0 or count==n:
    ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#S=input()
#import fractions
#lis=list(map(int,input().split()))

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

flag=-1
count=0
for i in range(n):
    if s[i]=="#":
        count+=1
        if flag==-1:
            flag=i
btw=count
wtb=n-count-flag
ans=min(btw,wtb)

print(ans)

Submission status: Wrong Answer

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

flag = False
countA = 0
countB = 0
T = []
for i in range(N):
  if S[i] == '#':
    for j in range(N):
      if j >= i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countA = countA + 1
    break

T = []
for i in reversed(range(N)):
  if S[i] == '.':
    for j in range(N):
      if j > i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countB = countB + 1
    break

if countA < countB and countA != 0:
  print(countA)
else:
  print(countB)

Submission status: Wrong Answer

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

flag = False
countA = 0
countB = 0
T = []
for i in range(N):
  if S[i] == '#':
    for j in range(N):
      if j >= i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countA = countA + 1
    break
print(T)

T = []
for i in reversed(range(N)):
  if S[i] == '.':
    for j in range(N):
      if j > i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countB = countB + 1
    break
print(T)

if countA < countB and countA != 0:
  print(countA)
else:
  print(countB)

Submission status: Wrong Answer

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

penals1 = []
penals2 = []
tmp1 = 0
tmp2 = 0

for i in range(N // 2 + 1):
    if S[i] == "#":
        tmp1 += 1
    
    if S[-(i+1)] == ".":
        tmp2 += 1
    penals1.append(tmp1)
    penals2.append(tmp2)
    #penals2.insert(0, tmp2)

#min_p = [penals2[-1]] + [penals1[i] + penals2[-i] for i in range(N // 2 + 1)]

if N % 2 == 0: 
    # i = N//2-1
    min_p = tmp1 + tmp2 # save
    #min_p = penals2[-1] + tmp2 # save
    i = N // 2  # right-> N // 2 
    j = N // 2 - 2 # left -> 0
elif N >= 3: 
    val1 = penals1[-1] + penals2[-2]
    #i = N//2-1
    #val1 = tmp1 + penals2[-2]
    #i = N//2-2
    val2 = penals1[-2] + penals2[-1]
    #val2 = penals1[-1] + tmp2
    min_p = min(val1, val2)
    i = (N-1) // 2 + 1  # right -> N // 2 
    j = (N-1) // 2 - 2 # left -> 0
else:
    min_p = 2 # dummy


#for i in range(N//2+1, N-1):
while i < N-1 and N >= 2:
    #assert j >= 0, "i=%d, j=%d" % (i, j)
    if S[i] == "#":
        tmp1 += 1
    if S[-(i+1)] == ".":
        tmp2 += 1

    # i = N//2+1 -> N-2
    val1 = tmp1 + penals2[j]
    
    # j = N//2-2 -> 0
    #print(j, penals1[j], tmp2)
    val2 = penals1[j] + tmp2 
    val = min(val1, val2)
    if val < min_p:
        min_p = val
    i += 1
    j -= 1

if S[N-1] == "#":
    tmp1 += 1
if S[0] == ".":
    tmp2 += 1

val = min(tmp1, tmp2)
if val < min_p:
    min_p = val

print(min_p)

Submission status: Wrong Answer

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

countA = 0
countB = 0
T = []
for i in range(N):
  if S[i] == '#':
    for j in range(N):
      if j >= i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countA = countA + 1
    break

T = []
for i in reversed(range(N)):
  if S[i] == '.':
    for j in range(N):
      if j > i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countB = countB + 1
    break

if countA < countB:
  print(countA)
else:
  print(countB)

Submission status: Wrong Answer

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

flag = False
countA = 0
countB = 0
T = []
for i in range(N):
  if S[i] == '#':
    for j in range(N):
      if j >= i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countA = countA + 1
    break
print(T)

T = []
for i in reversed(range(N)):
  if S[i] == '.':
    for j in range(N):
      if j > i:
        T.append('#')
      else:
        T.append('.')
      if S[j] != T[j]:
        countB = countB + 1
    break
print(T)

if countA < countB:
  print(countA)
else:
  print(countB)

Submission status: Wrong Answer

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

penals1 = []
penals2 = []
tmp1 = 0
tmp2 = 0

for i in range(N // 2 + 1):
    if S[i] == "#":
        tmp1 += 1
    
    if S[-(i+1)] == ".":
        tmp2 += 1
    penals1.append(tmp1)
    penals2.append(tmp2)
    #penals2.insert(0, tmp2)

#min_p = [penals2[-1]] + [penals1[i] + penals2[-i] for i in range(N // 2 + 1)]

if N % 2 == 0: 
    # i = N//2-1
    min_p = tmp1 + tmp2 # save
    #min_p = penals2[-1] + tmp2 # save
    i = N // 2  # right-> N // 2 
    j = N // 2 - 2 # left -> 0
elif N >= 3: 
    val1 = penals1[-1] + penals2[-2]
    #i = N//2-1
    #val1 = tmp1 + penals2[-2]
    #i = N//2-2
    val2 = penals1[-2] + penals2[-1]
    #val2 = penals1[-1] + tmp2
    min_p = min(val1, val2)
    i = N // 2  # right -> N // 2 
    j = N // 2 - 3 # left -> 0
else:
    min_p = 2 # dummy


#for i in range(N//2+1, N-1):
while i < N-1 and N >= 2:
    if S[i] == "#":
        tmp1 += 1
    if S[-(i+1)] == ".":
        tmp2 += 1

    # i = N//2+1 -> N-2
    val1 = tmp1 + penals2[j]
    
    # i = N//2-2 -> 0
    val2 = penals1[j+1] + tmp2 
    val = min(val1, val2)
    if val < min_p:
        min_p = val
    i += 1
    j -= 1

if S[N-1] == "#":
    tmp1 += 1
if S[0] == ".":
    tmp2 += 1

val = min(tmp1, tmp2)
if val < min_p:
    min_p = val

print(min_p)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flag = False
count_answer = 0

for i in range(N):
  if S[i] == '#':
    if flag is False:
      flag = True
    else:
      T = []
      count_temp = 0
      for j in range(N):
        if j >= i:
          T.append('#')
        else:
          T.append('.')
        if S[j] != T[j]:
          count_temp = count_temp + 1
      if count_answer > count_temp:
        count_answer = count_temp

print(count_answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
fi = s.count('.')
se = s.count('#')
ans = min(fi, se)
print(ans)

Submission status: Wrong Answer

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

flag = False
count_answer = 0
count_temp = 0

for i in range(N):
  if S[i] == '#':
    if flag is False:
      flag = True
    else:
      T = []
      for j in range(N):
        if j >= i:
          T.append('#')
        else:
          T.append('.')
      for j in range(N):
        if S[j] != T[j]:
          count_temp = count_temp + 1
      if count_answer > count_temp:
        count_answer = count_temp
      count_temp = 0
      print(T)

print(count_answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input())
ans = 10**6
s = S.count('#')
d = S.count('.')
ss = 0
dd = 0
for i in range(n):
    if (S[i] == '#'):
        ss += 1
    else:
        dd += 1
    ans = min(ss + d - dd, ans)


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input())
ans = 10**6
s = S.count('#')
d = S.count('.')
ss = 0
dd = 0
for i in range(n):
    if (S[i] == '#'):
        ss +- 1
    else:
        dd += 1
    ans = min(ss + d - dd, ans)


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
s.append("#")

w_cnt = 0
b_cnt = 0
cnt = 0
isLeft = True
for i in range(len(s)-1):
    if isLeft:
        if s[i] == "#":
            b_cnt += 1
    else:
        if s[i] == ".":
            w_cnt += 1

    if not isLeft and s[i] == "." and s[i+1] == "#":
        cnt += min(b_cnt, w_cnt)
        w_cnt, b_cnt = 0, 0
        isLeft = True

    if s[i] == "#" and s[i+1] == ".":
        isLeft = False

print(cnt)

# .##...####... ->
# ......#######

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input())
ans = 10**6
s = S.count('#')
d = S.count('.')
ss = 0
dd = 0
for i in range(n):
    if (S[i] == '#'):
        ss +- 1
    else:
        dd += 1
    ans = min(dd + s - ss, ans)
   
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input())
ans = S.count('.')
s = S.count('#')
d = S.count('.')
ss = 0
dd = 0
for i in range(n):
    if (S[i] == '#'):
        ss +- 1
    else:
        dd += 1
    ans = min(dd + s - ss, ans)


print(ans)

Submission status: Wrong Answer

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

a = []
#  .##..#.##.
w = s.count(".")
b = s.count("#")
m = min(w,b)

bb=0

for i in range(n):
    if s[i]=='.':
        w-=1
        a.append(w)
    if s[i]=='#':
        bb += 1
        a.append(bb+w)
if len(a)>0:
    I = min(a)
    print(min(m,I))
else:
    print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = []
#  .##..#.##.
w = s.count(".")
b = s.count("#")
m = min(w,b)

bb=0

for i in range(n):
    if s[i]=='.':
        w-=1
    if s[i]=='#':
        bb += 1
        a.append(bb+w)
if len(a)>0:
    I = min(a)
    print(min(m,I))
else:
    print(m)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
N = int(input())
S = list(input())
ans = S.count(".")
cnt = ans
for i in range(N-1):
    if S[i] == "#":
        cnt += 1
    else:
        cnt -= 1
    ans = min(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = []
#  .##..#.##.
w = s.count(".")
b = s.count("#")
m = min(w,b)

bb=0
I = float('inf')
for i in range(n):
    if s[i]=='.':
        w-=1
    if s[i]=='#':
        bb += 1
        a.append(bb+w)
        I = min(a)
print(min(m,n))

Submission status: Wrong Answer

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


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input())
ans = S.count('.')
c = 0
for i in range(n):
    if (S[i] == '.'):
        c += 1
    else:
        c -= 1
    ans = min(ans, c)


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input())
ans = S.count('.')
c = 0
for i in range(n):
    if (S[i] == '.'):
        c += 1
    else:
        c -= 1
    ans = min(ans, c)


print(c)

Submission status: Wrong Answer

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

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "#":
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**6
for i in range(n-1):
	if sl[i]=="#" and sl[i+1]==".":
		c = b[i] + w[n-1]-w[i]
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w[0]==1:
	for i in range(n-1):
		if w[i]==w[i+1]:
			w0=w[n-1]-w[i]
			break
if b[n-1]-b[n-2]==1:
	for i in range(n-1):
		if b[n-1-i]==b[n-1-i-1]:
			b0=b[n-1-i]
			break

if w0<res:
	res=w0
if b0<res:
	res=b0

print(res)

Submission status: Wrong Answer

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

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

        cnt += 1

if len(s) >= 2 and s[-2] == "#" and  s[-1] == ".":
    s[-1] = "#"
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()                                                      
list_S = list(S)
N1 = 0
list_X =[]
X = list_S.count('.')
list_X.append(X)
    
for color in list_S:
        list_S1 = list_S[N1]
        if list_S[N1] == '.':
            X -= 1
            list_X.append(X)
            N1 +=1
        else:
            X += 1
            list_X.append(X)
            N1 +=1

X = list_S.count('#') 
list_X.append(X)

print(list_X)
X_MIN = min(list_X)
print(X_MIN)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
lis = []
rtmp = 0
ltmp = 0
tmp = 0
l,r = 0,0

for i in range(n-1):
    if (s[i] != s[i+1]):
        #clis+= 1
        #print(i)
        rtmp = i+1
        ltmp = i
        for j in range(ltmp):
            if s[j] == '#':
                tmp += 1
        for j in range(rtmp,n):
            if s[j] == '.':
                tmp += 1
        lis.append(tmp)
        #print(lis)
    tmp = 0
    l,r = 0,0

if len(lis) == 0: 
    print(0)
else:
    print(min(lis))

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
if (s.count("#") == len(s)) or (s.count(".") == len(s)):
    print(0)
else:
    sharp_cnt = s.count("#")
    # print(s.count("#"))
    if s[len(s)-1] == "#":
        for i in reversed(range(0,len(s))):
            if s[i] == ".":
                x = len(s)-i-1
                break
        sharp_cnt -= x

    period_cnt = s.count(".")
    if s[0] == ".":
        for i in range(len(s)):
            if s[i] == "#":
                y = i
                break
        period_cnt -= y
    print(min(period_cnt,sharp_cnt))

Submission status: Wrong Answer

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

cnt = 0
for i in range(len(s)-1):
    if s[i] == '#' and s[i+1] == '.':
        s[i+1] = '#'
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
tmp = 0
white = s.count('.')
tmp += s[:white].count('#') + s[white:].count('.')
print(min(white, tmp))

Submission status: Wrong Answer

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

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "#":
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**5
for i in range(n-1):
	if sl[i]=="#" and sl[i+1]==".":
		c = b[i] + w[n-1]-w[i]
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w[0]==1:
	for i in range(n-1):
		if w[i]==w[i+1]:
			w0=w[n-1]-w[i]
			#print(w0)
			break
if b[n-1]-b[n-2]==1:
	for i in range(n-1):
		if b[n-1-i]==b[n-1-i-1]:
			b0=b[n-1-i]
			#print(b[n-1-i])
			break

if w0<res:
	res=w0
if b0<res:
	res=b0

print(res)

Submission status: Wrong Answer

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

black_sum = [0]*(N+1)
white_sum = [0]*(N+1)
ans = S.count('.')
for i in range(N):
    key_black = 0
    key_white = 0
    if S[i]=='#':
        key_black = 1
    else:
        key_white = 1

    black_sum[i+1]=black_sum[i]+key_black
    white_sum[i+1]=white_sum[i]+key_white
tmp = 0
for i in range(1,len(black_sum)):
    if black_sum[i] != black_sum[i-1]:
        left = black_sum[i] - 1 #境界左の黒石の数
        right = white_sum[-1]-white_sum[i]  #境界右の白石の数
        tmp = left + right
    ans = min(tmp,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
lis = []
rtmp = 0
ltmp = 0
tmp = 0
l,r = 0,0

for i in range(n-1):
    if (s[i] == '#' and s[i+1] == '.') or (s[i] == '.' and s[i+1] == '#'):
        #clis+= 1
        #print(i)
        rtmp = i+1
        ltmp = i
        for j in range(ltmp):
            if s[j] == '#':
                l += 1
        for j in range(rtmp,n):
            if s[j] == '.':
                r += 1
        lis.append(min(l,r))
        #print(lis)
    tmp = 0
    l,r = 0,0

if len(lis) == 0: 
    print(0)
else:
    print(min(lis))

Submission status: Wrong Answer

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

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "#":
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**5
for i in range(n-1):
	if sl[i]=="#" and sl[i+1]==".":
		c = b[i] + w[n-1]-w[i]
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w[0]==1:
	for i in range(n-1):
		if w[i]==w[i+1]:
			w0=w[n-1]-i
			break
if b[n-1]-b[n-2]==1:
	for i in range(n-1):
		if b[n-1-i]==b[n-1-i-1]:
			b0=b[n-1-i]
			#print(b[n-1-i])
			break

if w0<res:
	res=w0
if b0<res:
	res=b0

print(res)

Submission status: Wrong Answer

Solution code:
#C 
#毎回関数を呼ぶとおそくなる
n = int(input())
stones = input()
score = stones.count(".")
r = score
for i in range(n):
	if stones[i] == ".":
		r -= 1
	else:
		r += 1
	result = min(r, score)
print(result)