Problem:


Score : 300 points

Problem Statement

There are N stones arranged in a row. Every stone is painted white or black.
A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.

Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.
Find the minimum number of stones that needs to be recolored.

Constraints

1 \leq N \leq 2\times 10^5

S is a string of length N consisting of . and #.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the minimum number of stones that needs to be recolored.

Sample Input 1

3
#.#

Sample Output 1

1

It is enough to change the color of the first stone to white.

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

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

start_black = 0
for i in range(N):
    if S[i] == '#':
        start_black = i
        break

S = S[start_black:]

white = 0
black = 0
for i in range(len(S)):
    if S[i] == '#':
        black += 1
    else:
        white += 1

if black < white and S[-1] == '#':
    print(black-1)
elif black < white:
    print(black)
else:
    print(white)

Submission status: Wrong Answer

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

start_black = 0
for i in range(N):
    if S[i] == '#':
        start_black = i
        break

S = S[start_black:]

white = 0
black = 0
for i in range(len(S)):
    if S[i] == '#':
        black += 1
    else:
        white += 1

print(min(white, min(start_black, black)))

Submission status: Wrong Answer

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

W = [0]*N
B = [0]*N
white = 0
black = 0

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

    W[i] = white
    B[-i-1] = black

ans = N - max(white, black)
for i in range(N-1):
    tmp = abs((i+1)-W[i]) + abs((N-i-1)+B[i+1])
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Wrong Answer

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

start_black = 0
for i in range(N):
    if S[i] == '#':
        start_black = i
        break

S = S[start_black:]

white = 0
black = 0
for i in range(len(S)):
    if S[i] == '#':
        black += 1
    else:
        white += 1

print(min(white, black))

Submission status: Wrong Answer

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

start_black = 0
for i in range(N):
    if S[i] == '#':
        start_black = i
        break

S = S[start_black:]

print(S)
white = 0
black = 0
for i in range(len(S)):
    if S[i] == '#':
        black += 1
    else:
        white += 1

print(min(white, black))

Submission status: Wrong Answer

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

start_black = 0
for i in range(N):
    if S[i] == '#':
        start_black = i
        break

S = S[start_black:]

white = 0
black = 0
for i in range(len(S)):
    if S[i] == '#':
        black += 1
    else:
        white += 1

if black > white:
    print(white-1)
else:
    print(black)

Submission status: Wrong Answer

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

start_black = 0
for i in range(N):
    if S[i] == '#':
        start_black = i
        break

S = S[start_black:]

white = 0
black = 0
for i in range(len(S)):
    if S[i] == '#':
        black += 1
    else:
        white +=1

print(min(black, white))

Submission status: Wrong Answer

Solution code:
a = int(input())
l = input()
s = 0 
r = 0
t = 0
q = 0
for i in l :
  if i == "#":
    t +=1
    q =1
  if q ==1 and i == ".":
    s+=1
    r+=t
    t = 0
  
print(min(s,r))

Submission status: Wrong Answer

Solution code:
a = int(input())
l = input()
s = 0 
r = 0
t = 0
for i in l :
  if i == "#":
    t +=1
  if t >= 1 and i == ".":
    s+=1
    r+=t
    t = 0
  
print(min(s,r))

Submission status: Wrong Answer

Solution code:
a = int(input())
l = input()
s = 0 
r = 0
t = 0
for i in l :
  if i == "#":
    t +=1
  if t >= 1 and i == ".":
    s+=1
    r+=t
    t = 0
  
print(min(s,t))

Submission status: Wrong Answer

Solution code:
a = int(input())
l = input()
s = 0 
t = 0
for i in l :
  if i == "#":
    t +=1
  if t >= 1 and i == ".":
    s+=1
  
print(min(s,t))

Submission status: Wrong Answer

Solution code:
a = int(input())
l = input()
s = 0 
t = 0
for i in l :
  if i == "#":
    t = 1
  if t ==1 and i == ".":
    s+=1
  
print(s)

Submission status: Wrong Answer

Solution code:
a = int(input())
l = input()
s = 0 
t = 0
for i in l :
  if i == "#":
    t = 1
  if t and i == ".":
    s+=1
  
print(s)

Submission status: Wrong Answer

Solution code:
a = int(input())
l = input()
s = 0 
for i ,j in zip(l,l[1:]):
  if i + j == "#.":s+=1
print(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
r=0
b=0
ans=0
for i in S:
    if i=='#':
        r+=1
    elif i=='.':
        b+=1
if r>b:
   ans=b
else:
   ans=r
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
r=0
b=0
for i in S:
    if i=='#':
        r+=1
    elif i=='.':
        b+=1
if r>b:
   print(b)
else:
   print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# TPBC201C - Stones
import sys
input = sys.stdin.readline

n = int(input())
s = input()
ans = 0
blk = 0
for i in s:
    if i == "#":
        blk += 1
    else:
        if blk > 0:
            ans += 1
            blk -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
# TPBC201C - Stones
n = int(input())
s = input()
ans = n
bl_l = 0
wh_r = s.count(".")
for i in s:
    if i == "#":
        bl_l += 1
    else:
        wh_r -= 1
    ans = min(ans, bl_l + wh_r)
print(ans)

Submission status: Wrong Answer

Solution code:
##### TPBC201C - Stones
n = int(input())
s = input()
if len(set(s)) == 1:
    print(0)
else:
    ans = n + 1
    blk = s.count("#")
    b = 0
    for i, j in enumerate(s, start=1):
        if j == "#":
            b += 1
        ans = min(ans, b + n - i - (blk - b))
    print(ans)

Submission status: Wrong Answer

Solution code:
##### TPBC201C - Stones
n = int(input())
s = input()
if len(set(s)) == 1:
    print(0)
else:
    blk = s.count("#")
    if s[0] == "#":
        b = 1
    else:
        b = 0
    ans = b + n - 1 - (blk - b)
    for i, j in enumerate(s[1:], start=2):
        if j == "#":
            b += 1
        ans = min(ans, b + n - i - (blk - b))
    print(ans)

Submission status: Wrong Answer

Solution code:
##### TPBC201C - Stones
n = int(input())
s = input()
if len(set(s)) == 1:
    print(0)
else:
    ans = n
    blk = s.count("#")
    b = 0
    for i, j in enumerate(s, start=1):
        if j == "#":
            b += 1
        ans = min(ans, b + n - i - (blk - b))
    print(ans)

Submission status: Wrong Answer

Solution code:
# TPBC201C - Stones
n = int(input())
s = input()
print(min(s.count("#"), s.count(".")))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
accumulation = [0]

# start = time.time()

addition = 0

# N-黒の累積和で白の数と計算する
for i in range(0, N):
    addition = 0
    if S[i] == "#":
        addition = 1
    accumulation.append(accumulation[i] + addition)

#print(accumulation)

workmin = N
worksum = 0
for j in range(1, N + 1):
    # jまでの黒の累積和 + j以降の白の累積和の最小値が答え

    black = accumulation[j]
    white = N - j - (accumulation[N] - accumulation[j])

    if workmin > black + white:
        workmin = black + white

# print("{}までの黒(#)の個数の累積和：{}".format(j, black))
# print("{}以降の白(.)の個数の累積和：{}".format(j, white))

print(workmin)

Submission status: Wrong Answer

Solution code:
# C- Stones

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

#print(N)
#print(S)

# 普通にループ
white = 0
black = 0
for i in range(N):
    if S[i] == ".":
        white += 1
    else:
        black += 1

if white == 0 or black == 0:
    print("0")
else:
    if white > black:
        print(black)
    else:
        print(white)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans1 = S.count("#")#全部..........にするために必要な変更数
ans2 = S.count(".")#全部##########にするために必要な変更数
#ここから下は、....###########にするための変更数を累積和で求める。
L =[0]*(N+1)
for i in range(N):
    if S[i] == "#":
        L[i+1] = L[i] + 1
    else:
        L[i+1] = L[i]
ans3 = N
for i in range(1,N+1):
    if ans3 > 2*L[i]+N-i-L[N-1]:
        ans3 =  2*L[i]+N-i-L[N-1]
print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans1 = S.count("#")#全部..........にするために必要な変更数
ans2 = S.count(".")#全部##########にするために必要な変更数
#ここから下は、....###########にするための変更数を累積和で求める。
L =[0]*N
for i in range(N):
    if i == 0:
        if S[i] == "#":
            L[i] = 1
    else:
        if S[i] == "#":
            L[i] = L[i-1] + 1
        else:
            L[i] = L[i-1]
ans3 = N
for i in range(N):
    if ans3 > 2*L[i]+N-i-L[N-1]:
        ans3 =  2*L[i]+N-i-L[N-1]
print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans1 = S.count("#")#全部..........にするために必要な変更数
ans2 = S.count(".")#全部##########にするために必要な変更数
#ここから下は、....###########にするための変更数を累積和で求める。
L =[0]*N
for i in range(N):
    if i == 0:
        if L[i] == "#":
            L[i] = 1
    else:
        if L[i] == "#":
            L[i] = L[i-1] + 1
        else:
            L[i] = L[i-1]
ans3 = N
for i in range(N):
    if ans3 < 2*L[i]+N-1-i-L[N-1]:
        ans3 =  2*L[i]+N-i-L[N-1]-1
print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans1 = S.count("#")#全部..........にするために必要な変更数
ans2 = S.count(".")#全部##########にするために必要な変更数
#ここから下は、....###########にするための変更数を累積和で求める。
L =[0]*N
for i in range(N):
    if i == 0:
        if L[i] == "#":
            L[i] = 1
    else:
        if L[i] == "#":
            L[i] = L[i-1] + 1
ans3 = N
for i in range(N):
    if ans3 < 2*L[i]+N-1-i-L[N-1]:
        ans3 =  2*L[i]+N-i-L[N-1]-1
print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

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

z = '#.'
if z in s:
  print(s.count(z))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
n=len(s)
x = 0
for i in range(n):
    y1=0
    for j in reversed(range(i)):
        if s[j] == "#":
            y1 += 1
        else:
            break
    y2=0
    for k in range(i, n):
        if s[k] == ".":
            y2 += 1
        else:
            break

    x += min(y1, y2)
print(str(x))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - Stones
https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

"""
import sys


def solve(N, S):
    ans1 = 0
    prev = '@'
    for s in S:
        if prev == '#' and s == '.':
            ans1 += 1
            prev = '#'
        else:
            prev = s
    return ans1


def main(args):
    N = int(input())
    S = input()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - Stones
https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

"""
import sys


def solve(N, S):
    ans1 = 0
    prev = '@'
    for s in S:
        if prev == '#' and s == '.':
            ans1 += 1
            prev = '#'
        else:
            prev = s

    ans2 = 0
    nex = '@'
    for s in S[::-1]:
        if nex == '.' and s == '#':
            ans2 += 1
            nex = '#'
        else:
            nex = s
    return min(ans1, ans2)



def main(args):
    N = int(input())
    S = input()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w=[]
b=[]
if s[0]==".":
    w.append(1)
    b.append(0)
else:
    w.append(0)
    b.append(1)
for i in range(1,n):
    if s[i]==".":
        w.append(w[i-1]+1)
        b.append(b[i-1])
    else:
        w.append(w[i-1])
        b.append(b[i-1]+1)
ans=1000000
cnt=s.count(".")
for j in range(n):
    if ans>b[j]+cnt-w[j]:
        ans=b[j]+cnt-w[j]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
leng = len(s)
white = 0

for i in range(leng-1):
  if s[i] == '.':
    white += 1

ansb = leng - 1 - white

if s[-1] == '.':
  white += 1

print(min(ansb,white))

Submission status: Wrong Answer

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

diff = s.count('.')

difflist = [diff]

for i in s:
  if i == '.':
    diff += 1
  else:
    diff -= 1
    
  difflist.append(diff)
  
print(min(difflist))

Submission status: Wrong Answer

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

if (s.count('.') == 0):
  print('0');
  exit()
if (s.count('#') == 0):
  print('0');
  exit()

white = 0
black = 0


# for i in range(len(s)):
#   print(i, s[i])
# for i in range(len(s)-1, -1, -1):
#   print(i, s[i])
  

for i in range(len(s)):
  if s[i] == '.':
    break    

left_black = i

for i in range((i+1), len(s)):
  if s[i] == '#':
    break

count = 0
for j in range((i+1), len(s)):
  # print(j, s[j])
  if s[j] == '.':
    count += 1

right_white = count

# print(left_black, right_white)

white = left_black + right_white



for i in range(len(s)-1, -1, -1):
  if s[i] == '#':
    break

right_white = (n-1-i)
    
for i in range((i-1), -1, -1):
  if s[i] == '.':
    break

count = 0
for j in range((i-1), -1, -1):
  # print(j, s[j])
  if s[j] == '#':
    count += 1

right_white = count

# print(left_black, right_white)

black = left_black + right_white

if white < black:
  print(white)
else:
  print(black)

Submission status: Wrong Answer

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

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

if count <= s.count('#'):
  print(count)
else:
  print(s.count('#'))

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

if s.count('.') == 0 or s.count('#') == 0:
  print('0')
else:
  i=0
  for i in range(int(n)):
    if char_list[i] == '#':
      break

  s=s[i:]
  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:
    min_changes = n

    # look for all wb (.#) from left to right
    for i in range(1, n):
        if s[i-1] == '.' and s[i] == '#':
            # count number of b left and w right of wb
            changes = s[:i].count('#') + s[i:].count('.')
            if changes < min_changes:
                min_changes = changes

    print(min_changes)

Submission status: Wrong Answer

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

white = len([char for char in S if char == '.'])

result = 0
if white == 0:
    result = 0
else:
    result = 10 ** 6
    left_black = 0
    right_white = white
    for char in S:
        if char == '.':
            right_white -= 1
        else:
            left_black += 1
        result = min(result, right_white + left_black)
print(result)

Submission status: Wrong Answer

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

black = len([char for char in S if char == '#'])
white = N - black

result = 10 ** 6
left_black = 0
right_white = white
for char in S:
    if char == '.':
        right_white -= 1
    else:
        left_black += 1
    result = min(result, right_white + left_black)
print(result)

Submission status: Wrong Answer

Solution code:
def paint_black():
    hasBlack = False
    count = 0
    for char in S:
        if char == '.' and hasBlack:
            count += 1
        if char == '#' and not hasBlack:
            hasBlack = True
    return count

def paint_white():
    hasWhite = False
    count = 0
    for char in reversed(S):
        if char == '#' and hasWhite:
            count += 1
        if char == '.' and not hasWhite:
            hasWhite = True
    return count

if __name__ == "__main__":
    N = int(input())
    S = input()
    print(min(paint_black(), paint_white()))

Submission status: Wrong Answer

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

hasBlack = False

count = 0
for char in S:
    if char == '.' and hasBlack:
        count += 1
    if char == '#' and not hasBlack:
        hasBlack = True
print(count)

Submission status: Wrong Answer

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

def counting_distance(s1, s2):
    count = 0
    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1
    return count

white = s.count('.')
black = n - white

list_dist = []
s_changed = '.' * white + '#' * black
dist_tmp = counting_distance(s, s_changed)
list_dist.append(counting_distance(s, s_changed))

if black < white:
    for i in range(white, n):
        if s[i] ==  s_changed[i]:
            dist_tmp += 1
        else:
            dist_tmp -= 1
        list_dist.append(dist_tmp)
elif black > white:
    for i in reversed(range(0, white)):
        if s[i] == s_changed[i]:
            dist_tmp += 1
        else:
            dist_tmp -= 1
        list_dist.append(dist_tmp)
else:
    for i in range(white, n):
        if s[i] ==  s_changed[i]:
            dist_tmp += 1
        else:
            dist_tmp -= 1
        list_dist.append(dist_tmp)
    dist_tmp = counting_distance(s, s_changed)
    for i in reversed(range(0, white)):
        if s[i] == s_changed[i]:
            dist_tmp += 1
        else:
            dist_tmp -= 1
        list_dist.append(dist_tmp)

print(min(list_dist))

Submission status: Wrong Answer

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

count_list = []

black = 0
white = s.count('.')

for i in range(n):
    if s[i] == '#':
        black += 1
    if s[i] == '.':
        white -= 1
    count_list.append(black + white)

print(min(count_list))

Submission status: Wrong Answer

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

def counting_distance(s1, s2):
    count = 0
    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1
    return count

count_list = []

black = 0
white = s.count('.')

for i in range(n):
    if s[i] == '#':
        black += 1
    if s[i] == '.':
        white += 1
    count_list.append(black + white)

print(min(count_list))

Submission status: Wrong Answer

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

count_list = []

for i in range(n):
    black = 0
    white = 0
    for j in range(i):
        if s[j] == '#':
            black += 1
    for j in range(i, n):
        if s[j] == '.':
            white += 1
    count_list.append(black + white)

print(min(count_list))

Submission status: Wrong Answer

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

count_list = []

for i in range(n):
    black = s[:i].count('#')
    white = s[i:].count('.')
    count_list.append(black + white)

print(min(count_list))

Submission status: Wrong Answer

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

count_list = []

for i in range(n):
    count_list.append(s[:i].count('.') + s[i:].count('#'))

print(min(count_list))

Submission status: Wrong Answer

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

def counting_distance(s1, s2):
    count = 0
    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1
    return count

white = s.count('.')
black = n - white

list_dist = []
s_changed = '.' * white + '#' * black
dist_tmp = counting_distance(s, s_changed)
list_dist.append(counting_distance(s, s_changed))

if black <= white:
    for i in range(white, n):
        if s[i] ==  s_changed[i]:
            dist_tmp += 1
        else:
            dist_tmp -= 1
        list_dist.append(dist_tmp)
else:
    for i in reversed(range(0, white)):
        if s[i] == s_changed[i]:
            dist_tmp += 1
        else:
            dist_tmp -= 1
        list_dist.append(dist_tmp)

print(min(list_dist))

Submission status: Wrong Answer

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

def counting_distance(s1, s2):
    count = 0
    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1
    return count

white = s.count('.')
black = n - white

list_dist = []
s_changed = '.' * white + '#' * black
dist_tmp = counting_distance(s, s_changed)
list_dist.append(counting_distance(s, s_changed))

if black <= white:
    for i in range(white, n):
        if s[i] == s_changed[i]:
            dist_tmp += 1
        else:
            dist_tmp -= 1
        list_dist.append(dist_tmp)
else:
    for i in reversed(range(0, white-1)):
        if s[i] == s_changed[i]:
            dist_tmp += 1
        else:
            dist_tmp -= 1
        list_dist.append(dist_tmp)

print(min(list_dist))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

b = s.count("*")
b_l = 0
m = n - b

for i in range(n):
	b_l += (s[i] == "#")
	m = min(m ,2 * b_l + (n - i - 1) - b)
print(m)

Submission status: Wrong Answer

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

b = s.count("*")
b_l = 0
lst =[n - b]

for i in range(len(s)):
	b_l += (s[i] == "*")
	lst.append(2 * b_l + (n - i - 1) - b)
print(min(lst))

Submission status: Wrong Answer

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


min_count = n
index_list = [i for i in enumerate(s)]

for border in range(n):
	count = 0
	for i, bw in index_list:
		if i < border and bw == '#':
			count += 1
		elif i >= border and bw == '.':
			count += 1
            
		if count >= min_count:
			break

	if min_count > count:
		min_count = count

print(min_count)

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 + 1] = '#'
		c += 1

print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
# at position 0
l_b = 0
r_w = S.count('.')
 
needHand = 2 * 10**5
for i,v in enumerate(S):
  if S[i] == '#': #black
    l_b += 1
  else:
    r_w -= 1
  ret = l_b + r_w
  
  if ret <= needHand:
    needHand = ret
 
ans = needHand
print("{}".format(ans))

Submission status: Wrong Answer

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

# at position 0
l_b = 0
r_w = S.count('.')

needHand = 2 * 10**5
for i,v in enumerate(S):
  if S[i] == '#': #black
    l_b += 1
  else:
    r_w -= 1
  ret = l_b + r_w
  
  if ret < needHand:
    needHand = ret

ans = needHand
print("{}".format(ans))

Submission status: Wrong Answer

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

def countHand(st, pos):
  left_b = st[:pos].count('#')
  right_w = st[pos:].count('.')
  ans = left_b + right_w
  return ans
  
minHand = 2 * 10 **5
for i in range(len(S)):
  ret = countHand(S, i) 
  if ret <= minHand:
    minHand = ret

ans = minHand
print("{}".format(ans))

Submission status: Wrong Answer

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

w=0
for i in s:
        if i==".":
                w+=1

b=0
min=10**5+1
for i in range(len(s)):
        temp=0
        if s[i]=="#":
                b+=1
        if s[i]==".":
                w-=1
        temp=w+b
        if temp<min:
                min=temp

print(min)

Submission status: Wrong Answer

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

W = S.count('.')
B = 0
ans = N
if W == 0:
    print (0)
else:
    for i in range(0,N):
#        print (i)
        if S[i] == '#':
            B += 1
        else:
            W -= 1
        ans = min(ans, B+W)
    print (ans)

Submission status: Wrong Answer

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

W = S.count('.')
B = 0
ans = N
for i in range(0,N):
    if S[i] == '#':
        B += 1
    else:
        W -= 1
    ans = min(ans, B+W)
print (ans)

Submission status: Wrong Answer

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

black = S.count('#')
white = N - black

answer = 0
if (white > 0 and black > 0):
  answer = min(black, white)
  black_left = 0
  white_left = 0
  for i in range(N - 1):
    if (S[i] == '#'):
      black_left += 1
    else:
      white_left += 1
    black_right = black - black_left
    white_right = white - white_left
    print(black_left, white_right)
    answer = min(answer, black_left + white_right)

print(answer)

Submission status: Wrong Answer

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

white = 0
black = 0
for c in S:
  if (c == '#'):
    black += 1
  else:
    white += 1

answer = 0
if (white > 0 and black > 0):
  black_left = 0
  white_left = 0
  answer = N
  for i in range(N):
    if (S[i] == '#'):
      black_left += 1
    else:
      white_left += 1
    black_right = black - black_left
    white_right = white - white_left
    answer = min(answer, black_left + white_right)

print(answer)

Submission status: Wrong Answer

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

last = N - 1
while (last >= 0 and S[last] == '#'):
  last -= 1

answer = 0
if (last > 0):
  black = 0
  white = 0
  count_white = False
  for i in range(last + 1):
    if (S[i] == '#'):
      count_white = True
      black += 1
    else:
      if (count_white):
        white += 1
  answer = min(black, white)

print(answer)

Submission status: Wrong Answer

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

last = N - 1
while (last >= 0 and S[last] == '#'):
  last -= 1

answer = 0
if (last > 0):
  black = 0
  white = 0
  for i in range(last + 1):
    if S[i] == '#':
      black += 1
    else:
      white += 1
  answer = min(black, white)

print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ib = s.find('#')
ibr = s.rfind('#')
iw = s.rfind('.')
if iw < ibr:
  print('0')
  exit()
cw = s[ib:].count('.')
cb = s.count('#')
if ib == -1 or ib == n:
	print('0')
elif cw >= cb and cw >= cb - (n - 1 -iw):
	print(cb)
else:
	print(cw)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ib = s.find('#')
cw = s[ib:].count('.')
cb = s.count('#')
if ib == -1:
  print('0')
elif cw >= cb:
  if s[-1] == '#':
  	iw = s.rfind('.')
  	print(cb - (n - 1 - iw))
  else:
  	print(cb)
else:
  print(cw)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ib = s.find('#')
cw = s[ib:].count('.')
cb = s.count('#')
if ib == -1:
  print('0')
elif cw >= cb:
  print(cb)
else:
  print(cw)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ib = s.find('#')
cw = s[ib:].count('.')
cb = s.count('#')
if cw >= cb:
  print(cw)
else:
  print(cb)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(len(s)):

    if '#' not in s:
        print('0')
        break
        
    elif s[i]=='#':
        if s[len(s)-1]=='#':
            print(min(s[i:].count('.'),s.count('#')-1))
            break
        else:
            print(min(s[i:].count('.'),s.count('#')))
            break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(len(s)):

    if '#' not in s:
        print('0')
        break
        
    elif s[i]=='#':
        if s[len(s)-1]=='#':
            print(min(s[i:].count('.'),s[i:].count('#')-1))
            break
        else:
            print(min(s[i:].count('.'),s[i:].count('#')))
            break

Submission status: Wrong Answer

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

for i in range(len(s)):

    if '#' not in s:
        print('0')
        break
        
    elif s[i]=='#':
        print(min(s[i:].count('.'),s[i:].count('#')))
        break

Submission status: Wrong Answer

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

for i in range(len(s)):

    if '#' not in s:
        print('0')
        break
    
    elif s[i]=='#':
        print(s[i:].count('.'))
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
start = 0
ans1 = 0
ans2 = 0
re = ""
for i in range(len(s)):
    re += s[-i-1]
for i in re:
    if start != 0 or i != "#":
        start = 1
    if start == 1 and i == ".":
        ans1 += 1
for i in range(len(s)):
    if s[i] == "#":
        ans2 += 1
print(min(ans1, ans2))

Submission status: Wrong Answer

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

num_of_black = 0
num_of_white = 0
for v in S:
    if v == '#':
        num_of_black += 1
    else:
        num_of_white += 1

a = N - num_of_black
b = N - num_of_white
print(min(a,b))

Submission status: Wrong Answer

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

result = 0

for i in range(N-1):
  if S[i:i+2] == '#.':
    for j in range(i, -1, -1):
      if S[j] == '#':
        result += 1
      else:
        break

print(result)

Submission status: Wrong Answer

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

result = 0

for idx in range(N - 1):
  if S[idx:idx+2] == '#.':
    result += 1

print(result)

Submission status: Wrong Answer

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

S_t1 = [s for s in S]
c1 = 0
for i in range(1, len(S)):
  if S_t1[i-1]=='#' and S_t1[i]=='.':
    S_t1[i] = '#'
    c1 += 1
    
S_t2 = [s for s in S]
c2 = 0
for i in range(len(S)-1,0,-1):
  if S_t2[i-1]=='#' and S_t2[i]=='.':
    S_t2[i-1] = '.'
    c2 += 1
    
print(min(c1, c2))

Submission status: Wrong Answer

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

S_t1 = [s for s in S]
c1 = 0
for i in range(1, len(S)):
  if S_t1[i-1]=='#' and S_t1[i]=='.':
    S_t1[i] = '#'
    c1 += 1
    
S_t2 = [s for s in S]
c2 = 0
for i in range(len(S)-1,0,-1):
  if S_t2[i-1]=='#' and S_t2[i]=='.':
    S_t2[i-1] = '.'
    c2 += 1
    
print(min(c1, c2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
S_t1 = [s for s in S]
c1 = 0
for i in range(1, len(S)):
  if S_t1[i-1]=='#' and S_t1[i]=='.':
    S_t1[i] = '#'
    c1 += 1
    
S_t2 = [s for s in S]
c2 = 0
for i in range(len(S)-1,0,-1):
  if S_t2[i-1]=='#' and S_t2[i]=='.':
    S_t2[i] = '.'
    c2 += 1
    
print(min(c1, c2))

Submission status: Wrong Answer

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

S_t1 = [s for s in S]
c1 = 0
for i in range(1, len(S)):
  if S_t1[i-1]=='#' and S_t1[i]=='.':
    S_t1[i] = '#'
    c1 += 1
    
S_t2 = [s for s in S]
print(S_t2)
c2 = 0
for i in range(len(S)-1,0,-1):
  if S_t2[i-1]=='#' and S_t2[i]=='.':
    S_t2[i] = '.'
    c2 += 1
    
print(min(c1, c2))