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
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
S = li()
intS = [0] * N
for i in range(N):
    if S[i] == '#':
        intS[i] = 1
# print(intS)
acuS = list(accumulate(intS))
# print(acuS)
minS = 10 ** 9
for i in range(N):
    minS = min(minS, acuS[i] + (N-1-i) - (acuS[N - 1] - acuS[i]))
# print(minS)
print(minS)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
B,W = [],[]
key = '.'
ans = 10**9
i = 0

for s in S:
    if s == '#' and key == '.':
        W.append(i)
        i = 0
        key = '#'
    elif s == '.' and key == '#':
        B.append(i)
        i = 0
        key = '.'
    i += 1
W.append(i) if s == '.' else B.append(i)

for i in range(len(S)//2+1):
    ans = min(ans,sum(B[i:])+sum(W[:i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy

N = int(input())
S = [int(x) for x in input().replace('#', '1').replace('.', '0')]

# cumsum for black
res = numpy.cumsum(S)

min_count = N
for i in range(N):

    # for white
    w_num = i + 1
    # w_cur = w_num - res[i]
    w_rev = res[i]  # w_num - w_cur

    # for black
    b_num = N - w_num
    b_cur = res[-1] - res[i]
    b_rev = b_num - b_cur

    min_count = min(min_count, w_rev + b_rev)

print(min_count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
A=S
B=S[:: -1]
ans1=0
ans2=0

for i in range(N-1):
  if A[i]=='#' and A[i+1]=='.':
    A[i+1]='.'
    ans1 += 1

for i in range(N-1):
  if B[i]=='.' and B[i+1]=='#':
    B[i+1]='#'
    ans2 += 1

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import numpy
N=int(input())
S=input()
S_modify = list(map(int,S.replace('.','0').replace('#','1')))
count_list = []

sum_list=numpy.cumsum(S_modify)
for i in range(len(S_modify)):
    w_num = sum_list[i]
    b_num= (N-i-1)-sum(S_modify[(i+1):])
    count_list.append((w_num + b_num))
print(min(count_list))

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
S = str(input())
sign = ('.', '#')
if S.count('#') == 0 or S.count('.') == 0:
    print(0)
else:
    print(min(S.count('.'), S.count('#')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
flag=(S[0]=="#")
count=0
for i in range(1,len(S)):
    if not flag:
        flag=(S[i]=="#" and S[i-1]==".")
    if flag:
        if S[i]=="." and S[i-1]=="#":
            count+=1
            S[i]="#"
print(count)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
# s = "..#...#.."
s_list = list(s)
dot_cnt =0
sharp_cnt = 0
for i in range(0, len(s_list)-1):
    # print("i", i)
    if (s_list[i] == "#") and (s_list[i+1] == "."):
        for h in range(1,len(s_list)+1):
            if i+h == len(s_list):
                dot_cnt += h-1
                # print("dot_cnt_over", dot_cnt)
                break
            if s_list[i+h] == "#":
                dot_cnt += h-1
                # print("dot_cnt", dot_cnt)
                break
            # if i+h == len(s_list)-1:
            #     dot_cnt += h+1
            #     break
for i in range(1, len(s_list)):
    if (s_list[i] == ".") and (s_list[i-1] == "#"):
        for j in reversed(range(0,i)):
            if s_list[j] == ".":
                sharp_cnt += i-j-1
                break
            if j == 0:
                sharp_cnt += i
                break

print(min(dot_cnt, sharp_cnt))

Submission status: Wrong Answer

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

counter = 0
for i in range(n-1):
    if s[i] == "#":
        for j in range(n-1-i):
            if s[j+i+1] == ".":
                counter += 1
            else:
                pass
    break

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
x = 0
w = 0
b = 0
while S[x] == ".":
  x += 1
  if x == N:
    break
for j in range(N):
  if S[j] == ".":
    w += 1
  else:
    b += 1
if w - x <= b:
  print(w - x)
else:
  print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
for i in range(0,n) :
    if s[i] == '.' :
        continue
    elif s[i] == '#' :
        break
s = s[i:n]
for j in range(1,n-i+1) :
    if s[-j] == '.' :
        break
    elif s[-j] == '#' :
        continue
s = s[0:n-i-j+1]
x = s.count('#')
y = s.count('.')
print(min(x,y))

Submission status: Wrong Answer

Solution code:
SIRO = '.'
KURO = '#'
N = int(input())
S = input()
sLst = []
cnt = 1
if S[0] != '#':
    sLst.append(0)

for i in range(0, N - 1):
    if S[i] == S[i + 1]:
       cnt += 1
    else:
        sLst.append(cnt)
        cnt = 1
    if i == N - 2:
        sLst.append(cnt)
kCnt = 0
sCnt = 0
for i in range(0, len(sLst), 2):
    if len(sLst) >= i + 2:
        kCnt += sLst[i]
        sCnt += sLst[i + 1]
ans = min(kCnt, sCnt)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    S = list(_ for _ in input())

    S_num = []
    index = 0 
    now = ''
    if(S[0]=='#'):
        S_num.append(1)
        now = '#'
    else:
        S_num.append(-1)
        now = '.'
        
    for i in range(1,N):
        if(S[i]=='#' and now =='#'):
            S_num[index] +=1
        elif(S[i]=='.' and now =='.'):
            S_num[index] +=-1
        elif(S[i]=='#' and now !='#'):
            S_num.append(1)
            now = '#'
            index +=1
        elif(S[i]=='.' and now !='.'):
            S_num.append(-1)
            now = '.'
            index +=1
    # print(S_num)
    ans = 0
    b = 0
    w = 0
    # ###.#.. → 3,-1,1,-2 → 5,-2
    # #...#.. → 1,-3,1,-2 → 1,-2
    for i in range(len(S_num)-1):
        if(S_num[i]>0 and S_num[i+1]<0):
            # b += S_num[i]
            # w += -S_num[i+1]
            ans += min(S_num[i],-S_num[i+1])
            if((S_num[i] > -S_num[i+1]) and i+2 < len(S_num)-1):
                S_num[i+2] += S_num[i] -S_num[i+1]
    # ans = min(b,w)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c1 = [0] * N
c2 = [0] * N
ans = N
for i in range(N):
    c1[i] += c1[i - 1] + 1 * (S[i] == "#")
    c2[i] += c2[i - 1] + 1 * (S[i] == ".")
c1 = [0] + c1
c2 = [0] + c2
#print(c1)
#print(c2)
for i in range(N):
    #print(c1[i], c2[N] - c2[i])
    ans = min(ans, c1[i] + c2[N] - c2[i])
print(ans)

Submission status: Wrong Answer

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

cost=[]
left=0
right=0
for i in range(N):
	if S[i]=='#':
		right+=1

cost.append(N-right)
for i in range(0,N):
	if S[i]=='#':
		left+=1
		right-=1
	print(left,right)
	cost.append(left+N-i-1-right)

cost.sort()
print(cost[0])

Submission status: Wrong Answer

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

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]
		#print(c)
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]

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

print(res)
#print(w)
#print(b)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c1 = [0] * N
c2 = [0] * N
ans = N
for i in range(N):
    c1[i] += c1[i - 1] + 1 * (S[i] == "#")
    c2[i] += c2[i - 1] + 1 * (S[i] == ".")
c1 = [0] + c1
c2 = [0] + c2
print(c1)
print(c2)
for i in range(N):
    print(c1[i], c2[N] - c2[i])
    ans = min(ans, c1[i] + c2[N] - c2[i])
print(ans)

Submission status: Wrong Answer

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

b_count = [0]*(N+1)
w_count = [0]*(N+1)

for i in range(1,len(S)):
    if S[i] == "#":
        b_count[i] = b_count[i-1] + 1
    else:
        b_count[i] = b_count[i-1]

for i in range(len(S)-1,-1,-1):
    if S[i] == ".":
        w_count[i] = w_count[i+1] + 1
    else:
        w_count[i] = w_count[i+1]

#print(b_count)
#print(w_count)

res = float('inf')
for i in range(len(S)+1):
    tmp = b_count[i] + w_count[i]
    res = min(res,tmp)

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy

N = int(input())
S = [int(x) for x in input().replace('#', '1').replace('.', '0')]

res = numpy.cumsum(S)

min_count = N
for idx in range(N):
    # white
    white_num = idx + 1
    w_count = res[idx]

    # black
    black_num = N - white_num
    black_current = res[-1] - res[idx]
    b_count = black_num - black_current
    min_count = min(min_count, w_count + b_count)

print(min_count)

Submission status: Wrong Answer

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

b_count = [0]*(N+1)
w_count = [0]*(N+1)

for i in range(1,len(S)):
    if S[i] == "#":
        b_count[i] = b_count[i-1] + 1
    else:
        b_count[i] = b_count[i-1]

for i in range(len(S)-1,-1,-1):
    if S[i] == ".":
        w_count[i] = w_count[i+1] + 1
    else:
        w_count[i] = w_count[i+1]

#print(b_count)
#print(w_count)

res = float('inf')
for i in range(len(S)):
    tmp = b_count[i] + w_count[i]
    res = min(res,tmp)

print(res)

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()
for sidx in range(N):
	#print("a",sidx)

	if S[sidx]=="#":
		S=S[sidx:]
		break
#print(S)
if len(S)==0:
	print(0)
	exit()
if S[-1]==".":
	pass
else:
	count=-1
	while S[count] != ".":
		if count==-len(S):
			break
		count-=1
	S=S[:-count]
#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()
c1 = [0] * N
c2 = [0] * N
ans = N
for i in range(N):
    c1[i] += c1[i - 1] + 1 * (S[i] == "#")
    c2[i] += c2[i - 1] + 1 * (S[i] == ".")
c1 = [0] + c1
c2 = [0] + c2
for i in range(N):
    ans = min(ans, c1[i + 1] + c2[N] - c2[i + 1])
print(ans)

Submission status: Wrong Answer

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

if N == 1:
    print('0')
else:
    index = 0
    counter = 0
    while index < N:
        if S[index] == '#':
            offset = 1
            while index + offset < N and S[index + offset] == '#':
                offset += 1

            if index + offset == N:
                break
            else:
                count = 1
                memory = offset
                offset += 1
                while index + offset < N and S[index + offset] == '.':
                    offset += 1
                    if count < memory:
                        count += 1
                counter += count
                index += offset
        else:
            index += 1
    print(str(counter))

Submission status: Wrong Answer

Solution code:
#文字列から指定した文字の最初のインデックスを返す関数
def searchFirstIndex(string,search_chr):
    length = len(string)
    index = -1
    for i in range(length):
        if string[i] == search_chr:
            index = i
            break
    return index

#文字列の指定したインデックス以降に指定の文字がいくつ入っているか
def countChr(string,search_chr,index):
    length = len(string)
    counter = 0
    for i in range(index,length):
        if string[i] == search_chr:
            counter += 1
    return counter

#入力
N = int(input())
S = input()

#最初の黒の位置
first_index = searchFirstIndex(S,"#")

if first_index != -1:
    #最初の黒の位置以降の白の数
    whitenum = countChr(S,".",first_index)
    print(whitenum)
else:
    #黒が見つからなかったとき
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "#":
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []
for i in range(n):
  ans.append(b[i]+w[n-1]-w[i])
if n == 1:
  print("0")
else:
  print(min(ans))

Submission status: Wrong Answer

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

ans = N
for i in range(1, N):
    if lS[i] == lS[i-1]:
        continue
    else:
        left = lS[:i].count('#')
        right = lS[i:].count('.')
        ans = min(ans, left+right)

if ans == N:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
def chec(s):
    llis = []
    rlis = []
    lef = 0
    rig = 0
    rtmp = 0
    ltmp = 0
    na = len(s)
    for i in reversed(range(0,na-1)):
        if s[i] == '#' and s[i+1] == '.' :
            #clis+= 1
            #print(i)
            rtmp = i+1
            ltmp = i
            while ltmp != -1 and s[ltmp] == '#':
                lef += 1
                ltmp -= 1
            llis.append(lef)
            while rtmp != na and s[rtmp] == '.':
                rig += 1
                rtmp += 1
            rlis.append(rig)
        lef = 0
        rig = 0
        rtmp = 0
        ltmp = 0

    #print(llis)
    #print(rlis)
    clis = min(sum(llis),sum(rlis))
    return clis


n = int(input())
s = list(input())
print(chec(s))

Submission status: Wrong Answer

Solution code:
N=input()
S=input()
S_modify = list(map(int,S.replace('.','0').replace('#','1')))
count_list = []
for i in range(len(S_modify)):
    w_num =  sum(S_modify[0:(i+1)])
    b_num= len(S_modify[(i+1):])-sum(S_modify[(i+1):])
    count_list.append((w_num + b_num))
print(min(count_list))

Submission status: Wrong Answer

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

white = 0
black = 0
first_black_index = 0
last_white_index = N

for i in range(N):
  if S[i] == ".":
    first_black_index = i + 1
  else:
    break

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

if first_black_index != N or last_white_index != 0:

  S = S[first_black_index:last_white_index]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "#":
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []
for i in range(n):
  ans.append(b[i]+w[n-1]-w[i])
print(min(ans))

Submission status: Wrong Answer

Solution code:
from sys import exit

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

stack = []

black = 0
white = 0

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

ans = len(S)
for i in range(len(S)):
    if ans > black + white:
        ans = black + white

    if i == 0:
        continue
    if S[i] == '.':
        white -= 1
    else:
        black += 1

print(ans)

Submission status: Wrong Answer

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

white = 0
black = 0
first_black_index = 0
last_white_index = N

for i in range(N):
  if S[i] == ".":
    first_black_index = i + 1
  else:
    break

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

if first_black_index != N or last_white_index != 0:

  S = S[first_black_index:last_white_index-1]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "#":
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []
print(b)
print(w)
for i in range(n):
  ans.append(b[i]+w[n-1]-w[i])
print(min(ans))

Submission status: Wrong Answer

Solution code:
N=input()
S=input()
S_modify = list(map(int,S.replace('.','0').replace('#','1')))

count_list = []
for i in range(len(S_modify)):
    count = 0
    count += sum(S_modify[0:(i+1)])
    count += len(S_modify[(i+1):])-sum(S_modify[(i+1):])
    count_list.append(count)
print(min(count_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cnt = 0
narabi = []
befores = '#'
for S in s:
    if S == befores:
        cnt += 1
    else:
        narabi.append(cnt)
        befores = S
        cnt = 1
narabi.append(cnt)
if s[-1] == '#':
    narabi.append(0)
hennkann = s.count('.')
hashu = 0
dot = 1
for i in range(int(len(narabi) / 2)):
    hennkann = min(hennkann,hennkann - narabi[dot] + narabi[hashu])
    dot += 2
    hashu += 2
print(hennkann)

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()
for sidx in range(N):
	if S[sidx]=="#":
		S=S[sidx:]
		break
if len(S)==0:
	print(0)
	exit()
if S[-1]==".":
	pass
else:
	count=-1
	while S[count] != ".":
		if count==-len(S):
			break
		count-=1
	S=S[count]

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=list(input())
ans=0
for i in range(N-1):
  if S[i]=='#' and S[i+1]=='.':
    S[i+1]='.'
    ans += 1
print(ans)

Submission status: Wrong Answer

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

count_black = 0
count_white = 0
result_list = []

for i in range(n):
    for j in range(i + 1):
        if s[j] == "#":
            count_black += 1
    for k in range(n - i - 1):
        if s[k + i + 1] == ".":
            count_white += 1
    Sum = count_black + count_white
    result_list.append(Sum)
    count_black = 0
    count_white = 0

result = min(result_list)

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
m = n
counts = s[:].count(".")
for i in range(n):
    counts += s[i].count("#") - s[i].count(".")
    if m > counts:
        m = counts
        
print(m)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
S = list(input())
sum = [0]*(N+1)
ans = 100000000000
for i in range(N):
    key = 0
    if S[i]=='#':
        key = 1
    sum[i+1]=sum[i]+key
for i in range(1,len(sum)):
    if sum[i]-sum[i-1] != 0:
        left = sum[i]-0
        right = bisect.bisect_right(sum,sum[i])-1 - i
        tmp = left + right
        ans = min(tmp,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
def chec(s):
    llis = []
    rlis = []
    clis = 0
    lef = 0
    rig = 0
    rtmp = 0
    ltmp = 0
    flg = 0
    na = len(s)
    for i in reversed(range(0,na-1)):
        if i != na and s[i] == '#' and s[i+1] == '.' :
            #clis+= 1
            #print(i)
            rtmp = i+1
            ltmp = i
            while ltmp != -1 and s[ltmp] == '#':
                lef += 1
                ltmp -= 1
            llis.append(lef)
            while rtmp != na and s[rtmp] == '.':
                rig += 1
                rtmp += 1
            rlis.append(rig)
        lef = 0
        rig = 0
        rtmp = 0
        ltmp = 0

    #print(llis)
    #print(rlis)
    clis = min(sum(llis),sum(rlis))
    return clis


n = int(input())
s = list(input())
print(chec(s))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=s.count('.')
ans=[cnt]
for i in range(n):
    if s[i]=='.':
        cnt-=1
    ans.append(cnt)
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
x = 0
y = 0 
while S[x] == ".":
  x += 1
  if x == N:
    break
for j in range(N):
  if S[j] == ".":
    y += 1
print(y - x)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
x = 0
y = 0 
while S[x] == ".":
  x += 1
  if x == N:
    break
for j in range(N):
  if S[j] == ".":
    y += 1
print(y - x)
print(y - x)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
sum = 0
cnt = 0
for itr in range(N):
    if s[itr] == '#':
        cnt += 1
        continue
    if cnt > 0:
        sum += 1
        cnt = 0
print(sum)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()
if b[a-1]== '#':
    print(b.count('#.'))
elif b.count('#')<b.count('.'):
    print(b.count('#'))
else :
    print(b.count('.'))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
n = input()
s = raw_input()

m = n
for i in range(len(s) + 1):
    left = s[:i]
    right = s[i:]
    m = min(m, left.count('#') + right.count('*'))
print m

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
n = input()
s = raw_input()

m = 10 ** 6
for i in range(len(s) + 1):
    left = s[:i]
    right = s[i:]
    m = min(m, left.count('#') + right.count('*'))
print m

Submission status: Wrong Answer

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

if "#" not in s or "." not in s:
    print(0)
else:
    black=s.index("#")
    s=s[black:]
    count=s.count(".")
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
n = input()
s = raw_input()

min = 10 ** 6
for i in range(len(s) + 1):
    left = s[:i]
    right = s[i:]
    min = left.count('#') + right.count('*')
print min

Submission status: Wrong Answer

Solution code:
from numpy import*
from itertools import*
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")
 
l=[t,r]
x=[len(list(v))for k,v in groupby(s)if k=="#"]
y=[len(list(v))for k,v in groupby(s)if k=="."]
if len(x)>len(y):
    y=[0]+y
elif len(x)<len(y):
    x=[0]+x
else:
    if s[0]=="#":
        y=[0]+y
        x=x+[0]
    else:
        y=y+[0]
        x=[0]+x
 
x=array([0]+list(accumulate(x)))
y=array(list(accumulate(y[::-1]))[::-1]+[0])
print(min(x+y))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
ans=N
left_black=0
right_white=S.count(".")

for i in S:
    if i==".":
        right_white-=1
        ans=min(ans,left_black+right_white)
    else:
        left_black+=1
        ans=min(ans,left_black+right_white)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
B,W = [],[]
key = '#'
i = 0
 
for s in S:
    if s == '#' and key == '.':
        W.append(i)
        i = 0
        key = '#'
    elif s == '.' and key == '#':
        B.append(i)
        i = 0
        key = '.'
    i += 1
W.append(i) if s == '.' else B.append(i)
 
ans = 0
a = 0
for b,w in zip(B,W):
    a = b+w if w < b+a and b != 0 else 0
    ans += min(b+a,w)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input())
b=[]

for i in range(n):
  b.append(a[:i].count("#")+a[i:].count("."))

print(min(b))

Submission status: Wrong Answer

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

if N==1:
    print("0")
else:
    cnt = N
    cnt_left=0
    cnt_right=S.count(".")
    for i in range(N):
        if S[i] == "#":
            cnt_left += 1
        else:
            cnt_right -= 1

        if cnt_left + cnt_right < cnt:
            cnt = cnt_left + cnt_right
    print(cnt)

Submission status: Wrong Answer

Solution code:
def pro():
    _, s = input(), [s for s in input()]
    try:
        s = s[s.index("#"):]
    except ValueError:
        return print(0)

    if "." not in s:
        return print(0)

    back = 0
    for i in range(1, len(s)+1):
        if s[-i] == "#":
            back += 1
        else:
            break

    s2 = s[:-back]
    a = s.count(".")
    b = len(s) - a
    b2 = len(s2) - a

    if a > b:
        return print(b2)
    else:
        return print(a)

pro()

Submission status: Wrong Answer

Solution code:
N = int (input ())
S = str (input ())
 
def dot_num ():
    cnt = 0
    for i in range (N):
        if S [i] == '.':
            cnt += 1
    return cnt
 
def hash_num ():
    cnt = 0
    for i in range (N):
        if S [i] == '#':
            cnt += 1
    return cnt
 
dots = dot_num ()
hashes = hash_num ()
 
if S [0] == '.':
    dots -= 1
 
if S [N-1] == '#':
    hashes -= 1
    
print (min (dots, hashes))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=[str(i) for i in input().split()][0]
try:
    start=S.index("#")
    end=max([n for n,i in enumerate(S) if i=="."])
    X=S[start:end+1]
    sharpn=[i for i,n in enumerate(X) if n=="#"]
    list=[X[sharpn[i]:sharpn[i+1]] for i in range(0,(len(sharpn)-1))]
    sharp=[i.count("#") for i in list]
    dot=[i.count(".") for i in list]
    sharpr=[i for i in reversed(sharp)]
    dotr=[i for i in reversed(dot)]
    res=[sum(dotr[0:i]+sharpr[i:len(dotr)]) for i in range(0,len(dotr))]
    res2=min(res)
    print(res2)
except:
    print(0)

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()
for sidx in range(N):
	if S[sidx]=="#":
		S=S[sidx:]
		break
for sidx in range(len(S)):
	if S[-sidx-1]==".":
		S=S[:-sidx-1]
		break

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()

for i, c in enumerate(s):
    if c == "#":
        s = s[i:]
        break

if s.count("#") == 0 or s.count(".") == 0:
    print(0)
    exit()

tmp_b = 0
tmp_w = 0
k = 0
flag = False

for i, c in enumerate(s):
    if c == "#":
        if flag:
            if tmp_b > tmp_w:
                k += tmp_w
            else:
                k += tmp_b

            tmp_b = 0
            tmp_w = 0
            flag = False

        tmp_b += 1
    else:
        tmp_w += 1
        flag = True

    if i == len(s) - 1:
        if tmp_b > tmp_w:
            k += tmp_w
        else:
            k += tmp_b

print(k)

Submission status: Wrong Answer

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

for i in range(N):
    # 連続した'#'から'.'に変わった場合,'.'の出現をカウントする
    if S.find('#', i) != i:
        count += 1

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

print(count-b if a <= b else count)

Submission status: Wrong Answer

Solution code:

n = input()
s = input()
s_list = list(s)
dot_cnt =0
sharp_cnt = 0
for i in range(0, len(s_list)-1):
    # print("i", i)
    if s_list[i] == "#" and (s_list[i+1] == "."):
        for h in range(1,len(s_list)+1):
            if i+h == len(s_list):
                dot_cnt += h-1
                # print("dot_cnt_over", dot_cnt)
                break
            if s_list[i+h] == "#":
                dot_cnt += h-1
                # print("dot_cnt", dot_cnt)
                break
            # if i+h == len(s_list)-1:
            #     dot_cnt += h+1
            #     break
for i in range(1, len(s_list)):
    if s_list[i] == "." and (s_list[i-1] == "#"):
        for j in reversed(range(0,i)):
            if s_list[j] == ".":
                sharp_cnt += i-j-1
                break
            if j == 0:
                sharp_cnt += i
                break

print(min(dot_cnt, sharp_cnt))

##...

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
bs = [0] * (N + 1)
ws = [0] * (N + 1)
total = float("inf")
left_b = 0
right_w = 0
for i, s in enumerate(S):
    if s == "#":
        left_b += 1
        bs[i + 1] = left_b
for i in reversed(range(N)):
    if S[i] == ".":
        right_w += 1
        ws[i] = right_w

for i in range(N):
    total = min(total, ws[i+1] + bs[i])

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = s.count(".")
l = 0

ans = 10**9
for i in s:
    if i == ".":
        r -= 1
    else:
        l += 1
    ans = min(ans,l+r)
print(ans)