Problem:


Score : 300 points

Problem Statement

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
#.#

Sample Output 1

1

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

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

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

first_black = 0
for i in range(N):
    if (S[i] == '.'):
        continue
    else:
        first_black = i
        break

remain_white = 0
for j in range(first_black, N):
    if S[j] == '.':
        remain_white += 1

last_white = 0
for i in range(N - 1, -1, -1):
    if S[i] == '#':
        continue
    else:
        last_white = i
        break

remain_black = 0
for j in range(last_white):
    if S[j] == '#':
        remain_black += 1

print(min(remain_black, remain_white))

Submission status: Wrong Answer

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

first_black = 0
for i in range(N):
    if (S[i] == '.'):
        continue
    else:
        first_black = i
        break

remain_white = 0
for j in range(first_black, N):
    if S[j] == '.':
        remain_white += 1

last_white = 0
for i in range(N - 1, -1, -1):
    if S[i] == '#':
        continue
    else:
        last_white = i
        break

remain_black = 0
for j in range(i):
    if S[j] == '#':
        remain_black += 1

print(min(remain_black, remain_white))

Submission status: Wrong Answer

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

# # 単色のみの場合
# if '.' not in S:
#     print(0)
#     exit()
# elif '#' not in S:
#     print(0)
#     exit()

# それ以外
first_black = 0
white_count = 0
for i in range(N):
    if (S[i] == '.'):
        white_count += 1
    else:
        first_black = i
        break

remain_white = 0
for j in range(first_black, N):
    if S[j] == '.':
        remain_white += 1

last_white = 0
black_count = 0
for i in range(N - 1, -1, -1):
    if S[i] == '#':
        black_count += 1
    else:
        last_white = i
        break

remain_black = 0
for j in range(i + 1):
    if S[j] == '#':
        remain_black += 1

print(min(remain_black, remain_white))

Submission status: Wrong Answer

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

# 単色のみの場合
if '.' not in S:
    print(0)
    exit()
elif '#' not in S:
    print(0)
    exit()

# それ以外
first_black = 0
white_count = 0
for i in range(N):
    if (S[i] == '.'):
        white_count += 1
    else:
        first_black = i
        break

remain_white = 0
for j in range(first_black, N):
    if S[j] == '.':
        remain_white += 1

last_white = 0
black_count = 0
for i in range(N - 1, -1, -1):
    if S[i] == '#':
        black_count += 1
    else:
        last_white = i
        break

remain_black = 0
for j in range(i + 1):
    if S[j] == '#':
        remain_black += 1

print(min(remain_black, remain_white))

Submission status: Wrong Answer

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

# 単色のみの場合
if '.' not in S:
    print(0)
    exit()
elif '#' not in S:
    print(0)
    exit()

# それ以外
first_black = 0
white_count = 0
for i in range(N):
    if (S[i] == '.'):
        white_count += 1
    else:
        first_black = i
        break

remain_white = 0
for j in range(first_black, N):
    if S[j] == '.':
        remain_white += 1

print(remain_white)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


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


# In[9]:


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


# In[ ]:

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
for x,y in zip(S,S[1:]):
    ans+=((x=='#')and(y=='.'))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
countB=N
countW=0
i=0
while i<N:
    if S[i]=='.':
        countW+=1
    else:
        break
    i+=1

i=N-1
while i>=0:
    if S[i]=='#':
        countB-=1
    else:
        break
    i-=1

S=S[countW:countB]
print(min(S.count('.'),S.count('#')))

Submission status: Wrong Answer

Solution code:
stp = int(input()); s = [j for j in input()]; cut = ['#','.']
b,ans= [],0; ass = 0 if s.count('.') < s.count('#') else 1
for x,y in enumerate(s):
    if y == '#': b.append(x)
for i in reversed(b):
    if i+1 < stp: 
        if s[i+1] == '.': ans += 1; s[i] = cut[ass]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right


def solve():
    N = II()
    S = LS()

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

    ans = INF
    for i in range(N):
        if S[i] == '#':
            b += 1
        else:
            w -= 1
        ans = min(ans, b + w)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    S = LS()

    i = 0
    j = N-1
    ans = 0
    while 1:
    # for _ in range(100):
        for ii in range(i, N):
            si = S[ii]
            i = ii
            if si == '#':
                break

        for jj in range(j, -1, -1):
            sj = S[jj]
            j = jj
            if sj == '.':
                break
        if i >= j:
            break
        elif j - i == 1:
            ans += 1
            break
        else:
            ans += 2
            i += 1
            j -= 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
black_cnt = 0
white_cnt = 0
for i in range(N):
    if S[i] == '#':
        black_cnt += 1
    else:
        white_cnt += 1
ans = min(black_cnt, white_cnt)
tmp_ans = white_cnt
for i in range(N):
    if S[i] == '#':
        tmp_ans += 1
    else:
        tmp_ans -= 1
print(min(ans, tmp_ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if len(set(s)) == 1:
    print(0)
else:
    rs = s[::-1]
    f1 = s.index('#')
    f2 = n - rs.index('.') - 1
    # print(f1,f2)
    ans = min(s[f1:].count('.'), s[:f2].count('#'))
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if len(set(s)) == 1:
    print(0)
else:
    f1 = s.index('#')
    f2 = n - s[::-1].index('.')
    # print(f1,f2)
    ans = min(s[f1:].count('.'), s[:f2].count('#'))
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if len(set(s)) == 1:
    print(0)
else:
    f1 = s.index('#')
    f2 = n - s[::-1].index('.')
    # print(f1,f2)
    ans = min(s[f1:].count('#'), s[:f2].count('.'))
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    f = s.index('#')
    ans = s[f:].count('.')
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

acc_w = [0] * (N + 1)
acc_b = [0] * (N + 1)
for i in range(1, N + 1):
    c = S[i - 1]
    acc_w[i] = acc_w[i - 1] + (1 if c == '.' else 0)
    acc_b[i] = acc_b[i - 1] + (1 if c == '#' else 0)

ans = INF
for i in range(1, N + 1):
    now = acc_b[i] + acc_w[-1] - acc_w[i]
    ans = min(ans, now)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

left = -1 
right = N - 1
while left < N - 1 and S[left + 1] == '.':
    left += 1

cw = 0
acc = [0] * N
while right >= left:
    if S[right] == '.':
        cw += 1
    acc[right] = cw
    right -= 1

ans = acc[left]
cb = 0
for i, c in enumerate(S[left:]):
    if c == '#':
        cb += 1
    now = acc[i] + cb
    ans = min(ans, now)
print(ans)

Submission status: Wrong Answer

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

left = 0 
right = N
while left < N and S[left] == '.':
    left += 1
while right > 0 and S[right - 1] == '#':
    right -= 1

cb = 0
cw = 0
for c in S[left:right]:
    if c == '#':
        cb += 1
    else:
        cw += 1
print(min(cb, cw))

Submission status: Wrong Answer

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

found_b = False
cb = 0
cw = 0
for c in S:
    if c == '#':
        found_b = True
    if found_b:
        if c == '#':
            cb += 1
        else:
            cw += 1
print(min(cb, cw))

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]==".":
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
white = 0
black = 0
rightmost = -1
temp = 0
for i in range(n):
    if s[i] == '#':
        black+=1
    else:
        white+=1
        rightmost = i
        temp = black
print(min(n-white, n-black, temp))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

d=[0]*n
d2=[0]*n
d[0]=1 if s[0]=="#" else 0
d2[-1]=1 if s[-1]=="." else 0

for i in range(1,n):
  d[i]=d[i-1]+1 if s[i]=="#" else d[i-1]
  d2[-1-i]=d2[-i]+1 if s[-i-1]=="." else d2[-i]
  
print(d,d2)
m=n
for i in range(n):
  m=min(m,d[i]+d2[i])
print(m-1)

Submission status: Wrong Answer

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

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

print(min(whitecnt,blackcnt))

Submission status: Wrong Answer

Solution code:
n = int (input ())
s = input ()
x = 0
y = 0
for i in range (n):
  if s[i] == '#':
    x = 1
  else:
    if x == 1:
      y += 1
x = 0
z = 0
for i in range (n):
  if s[n-1-i] == '.':
    x = 1
  else:
    if x == 1:
      z += 1
if y < z:
  print (y)
else:
  print (z)

Submission status: Wrong Answer

Solution code:
n = int (input ())
s = input ()
x = 0
y = 0
for i in range (n):
  if s[i]=='#':
    x = 1
  else:
    if x == 1:
      y += 1
print (y)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
white = 0
black = 0
ans = 0

for s in S:
    if s == '#' and white == 0:
        black += 1
    elif s == '.' and black > 0:
        white += 1
    elif s == '#' and white > 0:
        ans += min(black,white)
        black = 1
        white = 0
else:
    ans += min(black,white)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
white = 0
black = 0
ans = 0

for s in S:
    if s == '#' and white == 0:
        black += 1
    elif s == '.' and black > 0:
        white += 1
    elif s == '#' and white > 0:
        ans += min(black,white)
        black = 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = S.replace('#.','')
print((N-len(S))//2)

Submission status: Wrong Answer

Solution code:
N,S = open(0).read().split()
N=int(N)
S=[s == "." for s in list(S)]

w = sum([1 if s else 0 for s in S])
b = 0
m = len(S)
for s in S:
    if s:
        w -= 1
    else:
        b += 1
    if m > w + b:
        m = w + b
print(m)

Submission status: Wrong Answer

Solution code:
N,S = open(0).read().split()
N=int(N)
S=list(S)

def calc():
    l = len(S)
    i = 0
    g = []
    while i < l:
        w = b = 0
        while i+w < l and S[i+w] == '.': w += 1
        while i+w+b < l and S[i+w+b] == '#': b += 1
        g.append(w)
        g.append(b)
        i += w + b

    i = 1
    j = len(g) - 2
    cnt = 0
    while i < j:
        if g[i+1] > g[j-1]:
            cnt += g[i]
            i += 2
        else:
            cnt += g[j]
            j -= 2
    return cnt

all_w = sum([1 if s == '#' else 0 for s in S])
all_b = sum([1 if s == '.' else 0 for s in S])
lwrb = calc()
print(min(all_w, all_b, lwrb))

Submission status: Wrong Answer

Solution code:
N,S = open(0).read().split()
N=int(N)
S=list(S)

def calc():
    group = [] if S[0] == '.' else [0]
    n = 0
    mark = S[0]
    for s in S:
        if s == mark:
            n += 1
        else:
            mark = s
            group.append(n)
            n = 1
    if n > 0:
        group.append(n)
    if S[-1] == '#':
        group.pop()

    cnt = 0
    i = 1
    j = len(group) - 1
    while i <= j:
        l = group[i]
        r = group[j]
        if l < r:
            cnt += l
            i += 2
        else:
            cnt += r
            j -= 2
    return cnt

all_w = sum([1 if s == '#' else 0 for s in S])
all_b = sum([1 if s == '.' else 0 for s in S])
lwrb = calc()
print(min(all_w, all_b, lwrb))

Submission status: Wrong Answer

Solution code:
N,S = open(0).read().split()
N=int(N)
S=list(S)

def makeGroup():
    group = [] if S[0] == '.' else [0]
    n = 0
    mark = S[0]
    for s in S:
        if s == mark:
            n += 1
        else:
            mark = s
            group.append(n)
            n = 1
    if n > 0:
        group.append(n)
    if mark == '#':
        group.append(0)
    return group

group = makeGroup()
i = 0
j = len(group) - 1
cnt = 0
wl = group[i]
br = group[j - 1]
while i < j:
    bl = group[i+1]
    wr = group[j]
    l = bl if wl <= bl else wl
    r = wr if wr <= br else br
    if l < r:
        cnt += l
        if wl <= bl:
            wl += l
        i += 2
    else:
        if br <= wr:
            br += r
        cnt += r
        j -= 2

print(cnt)

Submission status: Wrong Answer

Solution code:
N,S = open(0).read().split()
N=int(N)
S=list(S)

def makeGroup():
    group = [] if S[0] == '.' else [0]
    n = 0
    mark = S[0]
    for s in S:
        if s == mark:
            n += 1
        else:
            mark = s
            group.append(n)
            n = 1
    if n > 0:
        group.append(n)
    if mark == '#':
        group.append(0)
    return group

group = makeGroup()
i = 0
j = len(group) - 1
cnt = 0
wl = group[i]
wr = group[j]
while i < j:
    bl = group[i+1]
    br = group[j - 1]
    l = bl if wl <= bl else wl
    r = wr if wr <= br else br
    if l < r:
        cnt += l
        wl += l
        i += 2
    else:
        wr += l
        cnt += r
        j -= 2

print(cnt)

Submission status: Wrong Answer

Solution code:
N,S = open(0).read().split()
N=int(N)
S=list(S)

def makeGroup():
    group = [] if S[0] == '.' else [0]
    n = 0
    mark = S[0]
    for s in S:
        if s == mark:
            n += 1
        else:
            mark = s
            group.append(n)
            n = 1
    if n > 0:
        group.append(n)
    if mark == '#':
        group.append(0)
    return group

group = makeGroup()
i = 0
j = len(group) - 1
cnt = 0
while i < j:
    wl = group[i]
    bl = group[i+1]
    wr = group[j]
    br = group[j - 1]
    l = bl if wl <= bl else wl
    r = wr if wr <= br else br
    if l < r:
        cnt += l
        i += 2
    else:
        cnt += r
        j -= 2

print(cnt)

Submission status: Wrong Answer

Solution code:
N,S = open(0).read().split()
N=int(N)
S=list(S)

def count():
    group = [] if S[0] == '.' else [0]
    n = 0
    mark = S[0]
    for s in S:
        if s == mark:
            n += 1
        else:
            mark = s
            group.append(n)
            n = 1
    if n > 0:
        group.append(n)
    if mark == '#' and group:
        group.pop()
    return group

group = count()

def white():
    cnt = 0
    for i in range(2, len(group), 2):
        cnt += group[i]
    return cnt

def black():
    cnt = 0
    for i in range(1, len(group), 2):
        cnt += group[i]
    return cnt

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

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8').strip()
    idx = S.find('.')
    if idx == -1 or idx == N-1:
        print(0)
    else:
        count = S[idx:].count('.')
        change = min(count, N-idx-count)
        not_change = 0
        for s in S[::-1]:
            if s=='#':
                not_change += 1
            else:
                change -= not_change
                break
        print(change)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8').strip()
    idx = S.find('.')
    if idx == -1 or idx == N-1:
        print(0)
        sys.exit()
    else:
        count = S[idx:].count('.')
        change = min(count, N-idx-count)
        print(change)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

count2 = 0
S_inv = S[::-1]
for i in range(N):
    if S_inv[i] == '.':
        for j in range(i+1,N):
            if S_inv[j] == '#':
                count2 +=1
        break
        
print(min(count,count2))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
black=c.count("#")
white=c.count(".")

b=0
w=0
now=0
ans=float('inf')

for i in range(n):
  if c[i]=="#":
    b+=1
  elif c[i]==".":
    w+=1
  
  now=b+(white-w)
  ans=min(ans,now)
print(ans)

Submission status: Wrong Answer

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

stones = []

color = None
cnt = 0
for i in range(N):
    if color is None:
        color = S[i]
        cnt = 1
    elif color == S[i]:
        cnt += 1
    else:
        stones.append([color, cnt])
        color = S[i]
        cnt = 1
    if i == N-1:
        stones.append([S[i], cnt])

# print(stones)
ans = 0
for i in range(len(stones)-1):
    if stones[i][0] == '#' and stones[i+1][0] == '.':
        ans += min(stones[i][1], stones[i+1][1])

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
b2=s.count("#")
w2=s.count(".")
b1=0
w1=0
ans=n
for i in range(n):
    if s[i]=="#":
        b1+=1
        b2-=1
    else:
        w1+=1
        w2-=1
    ans=min(ans,b1+w2)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    s = input()
    cnt = [0]*(n)
    for i in range(n):
        cnt[i] = cnt[i-1]
        if s[i] == '#':
            cnt[i] += 1
    
    m = cnt[-1]
    ans = 10**9
    for i in range(n):
        tmp = cnt[i] + (n-i-1)-(m-cnt[i])
        ans = min(tmp, ans)
    print(ans)


        
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
switch=False
ans=0
for i in s:
    if switch==False:
        if i=="#":
            switch=True
    else:
        if i==".":
            ans+=1
switch=False
cnt=0
for i in s[::-1]:
    if switch==False:
        if i==".":
            switch=True
    else:
        if i=="#":
            cnt+=1
print(min(ans,cnt))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
occurred = False
for c in input():
    if c == '#':
        occurred = True
    elif occurred:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    S = input()
    w = S.count('.')
    if S[-1] == '.':
        print(min(w, N-w))
    else:
        print(min(w, N-1-w))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
s = input().rstrip()
sr = s[::-1]

sl = list(s)
srl = list(sr)

cnt = 0
cntr = 0
for i in range(1,len(sl)):
    if sl[i-1]=='#' and sl[i]=='.':
        cnt +=1
        sl[i]='#'
    if srl[i-1]=='.' and srl[i] == '#':
        cntr += 1
        srl[i]='.'
print(min(cnt,cntr))

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
s = input().rstrip()
sr = s[::-1]

#'.'より左にある#を探す
if '.' not in sr:
    ans = 0
else:
    c = sr.index('.')
    cc = sr[c:].count('.')
    cs = sr[c:].count('#')
    ans = min(cc,cs)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N = int(input())
S = list(input())
kuro = [0]*N
shiro = [0]*N
ans = N

for i in range(N):
    if S[i] == "#":
        kuro[i] = 1
    else:
        shiro[i] = 1
shiro.reverse()
shiro = list(accumulate(shiro))
kuro = list(accumulate(kuro))

for i in range(N-1):
    ans = min(ans, kuro[i]+shiro[N-i-2])

ans = min(ans, kuro[N-1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = list(input())
ans = Counter(S)
ans = min(ans["#"], ans["."])
kuro = 0
for i in range(N-1, -1, -1):
    if S[i] == ".":
        for j in range(i-1, -1, -1):
            kuro += S[j] == "#"
    else:
        continue
    break
print(min(ans, kuro))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = list(input())
ans = Counter(S)
ans = min(ans["#"], ans["."])
kuro = 0
total = 0
for i in range(N):
    kuro += S[i] == "#"
    if S[i] == ".":
        total += kuro
        kuro = 0
print(min(ans, total))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = list(input())
ans = Counter(S)
print(min(ans["#"], ans["."]))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

lis = [1 if s=='#' else 0 for s in S]
from itertools import accumulate
lis = list(accumulate(lis))

ans = 10**18
cnt = 0
for i in range(N-1, -1, -1):
    s = S[i]
    ans = min(ans, cnt+lis[i])
    if s=='.':
        cnt += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

lis = S.split('.')
maxl = 0
blacks = 0
for l in lis:
    maxl = max(len(l), maxl)
    blacks += maxl

print(blacks-maxl)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S=list(input())

    count1 = 0
    for s in S:
        if s == ".":
            count1 += 1
    
    count2 = 0
    for s in S:
        if s == "#":
            count2 += 1
    
    print(min(count1,count2))



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S=list(input())

    flag = False

    ans = 0
    for i in range(N):
        s = S[i]
        if s == "#":
            flag = True
        if s == ".":
            if flag:
                j = 1
                while i+j < N and S[i+j] != "#":
                    j += 1
                
                k = 1
                while i-1-k >= 0 and S[i-1-k]!= ".":
                    k += 1
                
                if j<k:
                    ans += j
                else:
                    ans += k

            flag = False

    print(ans)

    



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S=list(input())

    ans = 0
    flag = False
    for s in S:
        if s == "#":
            flag = True
        if s== ".":
            if flag:
                ans += 1
            flag = False

    print(ans)        



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S=list(input())

    ans = 0
    flag = False
    for s in S:
        if s == "#":
            flag = True
        elif flag:
            ans += 1
            flag = False

    print(ans)        



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

b, w = 0, 0
for i in range(N):
    if S[i] == '#':
        b += 1
    else:
        w += 1

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

print(ans)

Submission status: Wrong Answer

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

L = [[S[0], 1]]
cur = 0
for i in range(1, N):
    if S[i] == S[i-1]:
        L[cur][1] += 1
    else:
        L.append([S[i], 1])
        cur += 1

start, goal = 0, len(L)
if L[0][0] == '.':
    start += 1
if L[-1][0] == '#':
    goal -= 1

btw, wtb = 0, 0
for i in range(start, goal):
    if L[i][0] == '#':
        btw += L[i][1]
    else:
        wtb += L[i][1]

print(min(btw, wtb))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
wh = [0] * n
bl = [0] * n

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

ans = n
wtot = wh[-1]
btot = bl[-1]
for i in range(n):
  x = (wtot - wh[i]) + bl[i]
  ans = min(ans, x)
ans = min(ans, btot)
print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
wh = [0] * n
bl = [0] * n

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

ans = n
wtot = wh[-1]
btot = bl[-1]
for i in range(n):
  x = (wtot - wh[i]) + bl[i]
  print (x)
  ans = min(ans, x)
ans = min(ans, btot)
print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
wh = [0] * n
bl = [0] * n

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

ans = n
wtot = wh[-1]
btot = bl[-1]
for i in range(n):
  x = (wtot - wh[i]) + bl[i]
  ans = min(ans, x)
print (ans)

Submission status: Wrong Answer

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

ans = 0

wh,bl = 0,0
bl2,wh2 = 0,0

for i in range(n):
  if s[i] == '.':
    wh += 1
    if bl2 == 1:
      wh2 += 1
  else:
    if bl2 == 0:
      bl2 = 1
    bl += 1

ans = min(bl,wh,wh2)
print (ans)

Submission status: Wrong Answer

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

ans = 0

wh,bl = 0,0

for i in s:
  if i == '.':
    wh += 1
  else:
    if bl > 0 and wh > 0:
      ans += min(bl,wh)
      bl = 0
    wh = 0
    bl += 1
if bl > 0 and wh > 0:
  ans += min(bl, wh)
print (ans)

Submission status: Wrong Answer

Solution code:

import bisect

N = int(input())
S = '0'+input()+'0'

lst1 = []
lst2 = [0]*(N+2)


for i in range(1,N+1):
  if S[i] == '#':
    lst1.append(i)
  if S[N+1-i] == '.':
    lst2[N+1-i] = lst2[N+2-i] + 1
  else:
    lst2[N+1-i] = lst2[N+2-i]

if len(lst1) == N or lst2[1] == N:
  print(0)
  exit()
  
rlt = N+1
for i in range(len(lst1)):
  rlt =  min(rlt, i+lst2[lst1[i]])
  
print(rlt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
num=[]
str1="#"
num3=0
num2=0
if s[0]==".":
    num2=n
    for i in range(n):
        if s[i]==str1:
            num2=i
            break
for i in range(num2,n):
    if s[i]==str1:
        num3+=1
    else:
        if str1=="#":
            str1="."
        else:
            str1="#"
        num.append(num3)
        num3=1
num.append(num3)
numb=0
numw=0
for i in range(len(num)):
    if i%2==0:
        numb+=num[i]
    else:
        numw+=num[i]
print(min(numb,numw))