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

ans = 10**9
for i in range(N):
  ans = min(ans,c[0:i+1].count("#")+c[i+1:].count("."))
  
print(ans)

Submission status: Wrong Answer

Solution code:
import re
N=int(input())
l= input()
print(len(re.findall("#\.",l)))

Submission status: Wrong Answer

Solution code:
import re
N=int(input())
l= input()
print(len(re.findall("#.",l)))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w = S.count(".")
b = 0

ans = N
for i in range(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 = input()

bl = S.count("#")
print(min(bl, N-bl))

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

#with open('01.txt') as data:
    #lines = data.readlines()
    #N = int(lines[0].rstrip())
    #S = lines[1].rstrip()

N = ii()
S = input()

w_cnt = 0
b_cnt = 0

for i in S:
    if i == '.':
        w_cnt += 1
    else:
        break

for i in S[::-1]:
    if i == '#':
        b_cnt += 1
    else:
        break

w = b = 0

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

cnt = 0

for i in S:
    if i == '#':
        cnt += 1

#print(w_cnt, b_cnt, w, b)

print(min(w, b, cnt, N-cnt))

Submission status: Wrong Answer

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

f = False
w = 0
b = 0
buff = 0
for s in S[::-1]:
    if s == '.':
        buff += 1
        f = True
    if s == '#' and f:
        b += 1
        w += buff
        buff = 0
print(min(w, b))

Submission status: Wrong Answer

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

f = False
w = 0
b = 0
for s in S[::-1]:
    if s == '.':
        w += 1
        f = True
    if s == '#' and f:
        b += 1
print(min(w, b))

Submission status: Wrong Answer

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

    ans = 0
    c = None
    for s in S:
        if s == '.' and c == '#':
            ans += 1
        c = s

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_c

inf = 2 * 10 ** 5

WH = 0
BK = 1

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

dp = [[inf] * 2 for _ in range(n + 1)]
dp[0][WH] = 0

ret = 0
s = map(lambda c: 1 if c == '#' else 0, s)
for i, c in enumerate(s):
    if c == WH:
        dp[i + 1][WH] = min(dp[i][BK] + 1, dp[i][WH])
        dp[i + 1][BK] = min(dp[i][BK] + 1, inf)  # WH,WHをWH,BKに書き換えることはないためinf
    else:  # c == BK
        dp[i + 1][WH] = inf
        dp[i + 1][BK] = min(dp[i][BK], dp[i][WH])

print(min(dp[n]))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_c

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

s = reversed(s)
ret = 0
wt = False
for c in s:
    if c == '#':
        if wt:
            ret += 1
            wt = False
    else:
        wt = True

print(ret)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_c

n = int(input())
s = input() + '0'  # 番兵

ret = 0

j = 0
a, b = s[:2]

while b != '0':
    if a == '.':
        j += 1
        a, b = b, s[j + 1]
        continue

    # a == '#'

    if b == '#':
        j += 1
        a, b = b, s[j + 1]
        continue

    # b == '.'
    ret += 1
    j += 1
    a, b = '#', s[j + 1]

print(ret)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    inf = int(1e9)
    N = ri()
    S = rs()
    dp = [[inf] * N for i in range(2)]
    # forbidden : '#.'
    if S[0] == '.':
        dp[0][0] = 0
        dp[1][0] = 1
    else:
        dp[0][0] = 1
        dp[1][0] = 0
    for i in range(1, N):
        if S[i] == '.':
            dp[0][i] = min(dp[0][i], dp[0][i-1])
            dp[1][i] = min(dp[1][i], dp[0][i-1] + 1)
            dp[1][i] = min(dp[0][i], dp[1][i-1] + 1)
        else :
            dp[0][i] = min(dp[0][i], dp[0][i-1] + 1)
            dp[1][i] = min(dp[0][i], dp[0][i-1])
            dp[1][i] = min(dp[0][i], dp[1][i-1])
    print(min(dp[0][N-1], dp[1][N-1]))



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a = input()
b = input()
c = list(b)
while c[0] == "." : #左端の白を取り除いていく
    if (c[0] == ".") & (len(c) == 1): #列が白一個のみになったとき終了 
        break
    del c[0]
#この段階でcは["."]か["#",~~~]のどちらかである。    
while c[len(c)-1] == "#": #右端の黒を取り除いていく
    if (c[len(c)-1] == "#") & len(c) == 1: #列が黒一個のみになったとき終了
        break    
    del c[len(c)-1]
if c.count(".") <= c.count("#"): #白が黒より少ない場合
    d = c.count(".")
elif c.count(".") > c.count("#"): #白が黒より多い場合
    d = c.count("#")
print(d)

Submission status: Wrong Answer

Solution code:
a = input()
b = input()
c = list(b)
if len(c) >= 2:
    while c[0] == "." :
        del c[0]
        if (c[0] == ".") & (len(c) == 1): #列が白一個のみになったとき終了
            break
    while c[len(c)-1] == "#":
        if len(c) != 1:
            del c[len(c)-1]
        if (c[len(c)-1] == "#") & len(c) == 1:
            break    
    if c.count(".") <= c.count("#"): #白が黒より少ない場合
       d = c.count(".")
    elif c.count(".") > c.count("#"): #白が黒より多い場合
       d = c.count("#")
else: 
    d = 0
print(d)

Submission status: Wrong Answer

Solution code:
H = int(input().strip())
S = input().strip()
#print(H)
#print(S)
counter = 0
white = ''
step = 0
for i in S:
    if i == '.':
        white = white + '.'
    else:
        break
remainder = S[len(white):]
#print(white)
#print(remainder)
for i in remainder:
    if i == '#':
        counter += 1
paintWhite = 0
paintBlack = 0
if counter > len(remainder) / 2:
    print(len(remainder) - counter)
else:
    print(counter)

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
 
list1 = list(s)
 
k = 0
j = 0
result = 0
y = 0
 
for i in range(int(n)):
 
    if list1[i] == "#":
        k = 1
        # print("k = " + str(k))
 
    if k == 1:
        if list1[i] == ".":
            j = 1
        else:
            y + 1

    if k == 1 and j == 1:
        result = result + 1
        k = 0
        j = 0
        # print("k and j")
    else:
        y + 1

    if y == 2:
        k = 0
 
print(result)

Submission status: Wrong Answer

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

must = False
c1 = 0
for s in S:
    if s == '#':
        must = True
    if s == '.':
        if must:
            c1 += 1
T = S[::-1]
must = False
c2 = 0
for t in T:
    if t == '.':
        must = True
    if t == '#':
        if must:
            c2 += 1
print(min(c1, c2))

Submission status: Wrong Answer

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

must = False
c = 0
for s in S:
    if s == '#':
        must = True
    if s == '.':
        if must:
            c += 1
print(c)

Submission status: Wrong Answer

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

list1 = list(s)

k = 0
j = 0
result = 0

for i in range(int(n)):

    if list1[i] == ".":
        k = k + 1

    if k == 1:
        if list1[i] == "#":
            j = j + 1
        
    if k == 1 and j == 1:
        result = result + 1
        k = 0
        j = 0

print(result)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = list(str(input()))
li = collections.Counter(S)
if li.most_common()[0][1]==N:
    print(0)
else:
    print(li.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
count = idx = 0
flag = 1
for i in range(N):
    if flag == 1 and S[i-1]=="#" and S[i]=='.':
        flag = 0
        idx = i
        break
if flag==1:
    print(0)
else:
    print(S[idx:].count("."))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
memo=0
ans=0
for i in range(n):
    if s[i]=="#":
        memo=1
    else:
        if memo==0:
            pass
        else:
            ans+=1
print(ans)

Submission status: Wrong Answer

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


num_w = S.count('.')
num_b = N - num_w

l_b = 0
k = N

for i in S:
    if i == '.':
        num_w -= 1
        n_k = l_b + num_w
    else:
        l_b += 1
        n_k = l_b + num_w
    if n_k <= k:
        k = n_k
    else:
        break
if N-num_b < n_k:
    print(N-num_b)
elif num_b < n_k:
    print(num_b)
else:
    print(n_k)

Submission status: Wrong Answer

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

print(S)

num_w = S.count('.')
num_b = N - num_w

l_b = 0
k = N

for i in S:
    if i == '.':
        num_w -= 1
        n_k = l_b + num_w
    else:
        l_b += 1
        n_k = l_b + num_w
    if n_k <= k:
        k = n_k
    else:
        break
if N-num_b < n_k:
    print(N-num_b)
elif num_b < n_k:
    print(num_b)
else:
    print(n_k)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li=[]
for i in range(n+1):
    g=s[:i].count(".")+s[i:].count("#")
    li.append(g)
li.sort()
print(li[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
t=""
m=10000
g=0
for i in range(n):
    if s[i]==".":
        t+="0"
    else:
        t+="1"
for i in range(n):
    s1="0"*i+"1"*(n-i)
    g=0
    for j in range(n):
        if t[j]!=s1[j]:
            g+=1
    if m>g:
        m=g
print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
bl=0 
wh=0
for i in range(n):
    if s[i]=='#':
       bl+=1
a=bl

for j in range(n):
    if s[j]=='.':
        wh+=1
b=wh
if b>a:
  print(a)
elif a>b:
    print(b)

Submission status: Wrong Answer

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

best = n
curr = 0
nblack = 0

for ch in s:
  if ch == '.':
    curr = min(nblack, 1 + curr)
  else:
    nblack += 1
  best = min(best, curr)

print(best)

Submission status: Wrong Answer

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

cb = S.count("#")
cw = S.count(".")

if cb == 0:
	ans = 0
else:
	x = 0
	y = cw
	ans = float("inf")
	for i in range(N):
		if S[i] == "#":
			v = x + y
			if ans > v:
				ans = v
			x += 1
		else:
			v = x + y
			if ans > v:
				ans = v
			y -= 1

print(ans)

Submission status: Wrong Answer

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

cb = S.count("#")
cw = S.count(".")

if cb == 0:
	ans = 0
else:
	x = 0
	y = cw
	ans = float("inf")
	for i in range(N):
		if S[i] == "#":
			v = x + y
			if ans > v:
				ans = v
			x += 1
		else:
			y -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
rS = S[::-1]

ans1 = 0
x = S.find("#")
if x != -1:
	for i in range(x, N):
		if S[i] == ".":
			ans1 += 1

ans2 = 0
y = rS.find(".")
if y != -1:
	for i in range(y, N):
		if rS[i] == "#":
			ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

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

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

res1 = s.count(".")
res2 = s.count("#")
res3 = s[:-2].count("#")
if s[-1]==".":
    res3 += 1

print(min(res1,res2,res3))

Submission status: Wrong Answer

Solution code:
n = input()
s = list(input())
black = s.count("*")
white = len(s) - black
total, lb = [], 0
for i in range(len(s)):
	lb += s[i] == "*"
	total.append(white - (i+1) + lb * 2)
print(min(total))

Submission status: Wrong Answer

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

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

print(0)

Submission status: Wrong Answer

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

W = S.count('.')
for i in range(N):
    if S[i] == '#' and i != N-1:
        ans = min(N-W, N-i, W)
        print(ans)
        quit()
    elif S[i] == '#' and i == N-1:
        print(0)
        quit()

print(0)

Submission status: Wrong Answer

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

W = S.count('.')
for i in range(N):
    if S[i] == '#' and i != N:
        ans = min(N-W, N-i, W)
        print(ans)
        quit()
    elif S[i] == '#' and i == N:
        print(0)
        quit()

print(0)

Submission status: Wrong Answer

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

W = S.count('.')
for i in range(N):
    if S[i] == '#':
        ans = min(N-W, N-i, W)
        print(ans)
        quit()

print(0)

Submission status: Wrong Answer

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

first_black = N
black = 0
fail_white = 0
for i in range(N):
  if str[N-1-i] == '#':
    first_black = N-1-i
    black += 1
for i in range(first_black,N):
  if str[i] == '.':
    fail_white += 1
print(min(fail_white, black))

Submission status: Wrong Answer

Solution code:
import math

def main(n,s):
    prev = ''
    ar = []
    for i in s:
        if prev == '' or prev[0] == i:
            prev += i
        else:
            ar.append(prev)
            prev = i
    ar.append(prev)
    if len(ar) > 0 and ar[-1].count('#') > 0:
        ar.pop(-1)
    if len(ar) > 0 and ar[0].count('.') > 0:
        ar.pop(0)
    tmp = {
        "black": 0,
        "white":0
    }
    prev = ''
    for a in ar:
        if prev.count('#') > 0: # when '.'
            cur = {
                "black": tmp["black"] + len(prev),
                "white": tmp["white"] + len(a)
            }
        elif prev.count('.') > 0:
            cur = {
                "black": tmp["black"],
                "white": tmp["white"]
            }
        else:
            cur = {
                "black": tmp["black"],
                "white": tmp["white"]
            }
        if a.count('.') > 0:
            tmp["white"] += len(a)
        if (tmp["black"] + tmp["white"]) >= (cur["black"] + cur["white"]):
            tmp["black"] = cur["black"]
            tmp["white"] = cur["white"]
        prev = a
    print tmp["black"] + tmp["white"]
    return tmp["black"] + tmp["white"]

if __name__ == "__main__":
    n = int(raw_input())
    s = raw_input()
    main(n,s)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
L = len(S)
i = 0
while i < L:
    if S[i] == "#":
        break
    i += 1
if i == L:
    print(0)
else:
    count = 0
    for j in range(i,L):
        if S[j] == ".":
            count += 1
    if L - (count + i) <= count:
            print(L - count - i)
    else:
            print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
L = len(S)
i = 0
while i < L:
    if S[i] == "#":
        break
    i += 1
if i == L:
    print(0)
else:
    count = 0
    for j in range(i,L):
        if S[j] == ".":
            count += 1
    print(count)

Submission status: Wrong Answer

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

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

for c in s:
    if c == "#":
        if flag:
            k += tmp_b if tmp_b < tmp_w else tmp_w
            tmp_b = 0
            tmp_w = 0
            flag = False
        start_flag = True
        tmp_b += 1
    else:
        if start_flag:
            tmp_w += 1
            flag = True
else:
    k += tmp_b if tmp_b < tmp_w else tmp_w

print(k)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか


firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(0)
    sys.exit()
# if int(firstblack) == int(N):
#     print(1) # 最後のみひっくり返す
#     sys.exit()

check1 = S[(firstblack+1):]
edgeblack = check1.rfind('.') + 1
if int(edgeblack) == int(0):
    print(0)
    sys.exit()

if int(edgeblack) == int(len(check1)-1):
    check2 = check1
    blacknum = check2.count('#') # 黒の個数を返す
    whitenum = check2.count('.') # 白の個数を返す
    if whitenum <= blacknum:
        print(whitenum)
    else:
        print(blacknum + 1)
else:
    check2 = check1[:edgeblack]
    blacknum = check2.count('#') # 黒の個数を返す
    whitenum = check2.count('.') # 白の個数を返す

    if whitenum <= blacknum:
        print(whitenum)
    else:
        print(blacknum + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか


firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(0)
    sys.exit()
if int(firstblack) == int(N):
    print(1)
    sys.exit()

check1 = S[(firstblack+1):]
edgeblack = check1.rfind('.') + 1
if int(edgeblack) == int(0):
    print(0)
    sys.exit()

if int(edgeblack) == int(len(check1)-1):
    check2 = check1
    blacknum = check2.count('#') # 黒の個数を返す
    whitenum = check2.count('.') # 白の個数を返す
    if whitenum <= blacknum:
        print(whitenum)
    else:
        print(blacknum + 1)
else:
    check2 = check1[:edgeblack]
    blacknum = check2.count('#') # 黒の個数を返す
    whitenum = check2.count('.') # 白の個数を返す

    if whitenum <= blacknum:
        print(whitenum)
    else:
        print(blacknum + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか


firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(0)
    sys.exit()
if int(firstblack) == int(N):
    print(1)
    sys.exit()

check1 = S[(firstblack+1):]
edgeblack = check1.rfind('.') + 1
if int(edgeblack) == int(0):
    print(0)
    sys.exit()

if int(edgeblack) ==int(len(check1)-1):
    check2 = check1 
    blacknum = check2.count('#') # 黒の個数を返す
    whitenum = check2.count('.') # 白の個数を返す
    if whitenum <= blacknum:
        print(whitenum)
    else:
        print(blacknum + 1)
else:
    check2 = check1[:edgeblack]
    blacknum = check2.count('#') # 黒の個数を返す
    whitenum = check2.count('.') # 白の個数を返す

    if whitenum <= blacknum:
        print(whitenum)
    else:
        print(blacknum + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか


firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(0)
    sys.exit()
if int(firstblack) == int(N):
    print(1)
    sys.exit()

check1 = S[(firstblack+1):]
edgeblack = check1.rfind('.') + 1
if int(edgeblack) == int(0):
    check2 = check1 
    blacknum = check2.count('#') # 黒の個数を返す
    whitenum = check2.count('.') # 白の個数を返す
    if whitenum <= blacknum:
        print(whitenum)
    else:
        print(blacknum + 1)
else:
    check2 = check1[:edgeblack]
    blacknum = check2.count('#') # 黒の個数を返す
    whitenum = check2.count('.') # 白の個数を返す

    if whitenum <= blacknum:
        print(whitenum)
    else:
        print(blacknum + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか

# if int(N) != len(S):
#     print('桁数の不一致')
#     sys.exit()
# for moji in S:
#     if ('.' or '#') != moji:
#         print('文字列が条件範囲外')
#         sys.exit()

# pattern 1:黒の右を全て黒
firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(0)
    sys.exit()
if int(firstblack) == int(N):
    print(1)
    sys.exit()
check1 = S[(firstblack+1):]
check2 = check1[:check1.rfind('.')]
blacknum = check2.count('#') # 黒の個数を返す
whitenum = check2.count('.') # 白の個数を返す

if whitenum <= blacknum:
    print(whitenum)
else:
    print(blacknum + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか

# if int(N) != len(S):
#     print('桁数の不一致')
#     sys.exit()
# for moji in S:
#     if ('.' or '#') != moji:
#         print('文字列が条件範囲外')
#         sys.exit()

# pattern 1:黒の右を全て黒
firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(0)
    sys.exit()
if int(firstblack) == int(N):
    print(1)
    sys.exit()
check1 = S[(firstblack+1):]
check2 = check1[:check1.rfind('.'):]
blacknum = check2.count('#') # 黒の個数を返す
whitenum = check2.count('.') # 白の個数を返す

if whitenum <= blacknum:
    print(whitenum)
else:
    print(blacknum + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか

# if int(N) != len(S):
#     print('桁数の不一致')
#     sys.exit()
# for moji in S:
#     if ('.' or '#') != moji:
#         print('文字列が条件範囲外')
#         sys.exit()

# pattern 1:黒の右を全て黒
firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(0)
    sys.exit()
if int(firstblack) == int(N):
    print(1)
    sys.exit()
check = S[(firstblack+1):]
blacknum = check.count('#') # 黒の個数を返す
whitenum = check.count('.') # 白の個数を返す

if whitenum <= blacknum:
    print(whitenum)
else:
    print(blacknum + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか

# if int(N) != len(S):
#     print('桁数の不一致')
#     sys.exit()
# for moji in S:
#     if ('.' or '#') != moji:
#         print('文字列が条件範囲外')
#         sys.exit()

# pattern 1:黒の右を全て黒
firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(0)
    sys.exit()
if int(firstblack) == int(N):
    print(1)
    sys.exit()
check = S[(firstblack+1):]
blacknum = check.count('#') # 黒の個数を返す
whitenum = check.count('.') # 白の個数を返す

if whitenum <= blacknum:
    print(whitenum)
else:
    print(blacknum)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか

# if int(N) != len(S):
#     print('桁数の不一致')
#     sys.exit()
# for moji in S:
#     if ('.' or '#') != moji:
#         print('文字列が条件範囲外')
#         sys.exit()

# pattern 1:黒の右を全て黒
firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(1)
    sys.exit()
if int(firstblack) == int(N):
    print(1)
    sys.exit()
check = S[(firstblack+1):]
blacknum = check.count('#') # 黒の個数を返す
whitenum = check.count('.') # 白の個数を返す

if whitenum <= blacknum:
    print(whitenum)
else:
    print(blacknum)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか

# if int(N) != len(S):
#     print('桁数の不一致')
#     sys.exit()
# for moji in S:
#     if ('.' or '#') != moji:
#         print('文字列が条件範囲外')
#         sys.exit()

# pattern 1:黒の右を全て黒
firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(1)
    sys.exit()
check = S[(firstblack+1):]
blacknum = check.count('#') # 黒の個数を返す
whitenum = check.count('.') # 白の個数を返す

if whitenum <= blacknum:
    print(whitenum)
else:
    print(blacknum)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか

# if int(N) != len(S):
#     print('桁数の不一致')
#     sys.exit()
# for moji in S:
#     if ('.' or '#') != moji:
#         print('文字列が条件範囲外')
#         sys.exit()

# pattern 1:黒の右を全て黒
firstblack = S.find('#') # ない場合は-1を返す
if int(firstblack) == int(-1):
    print(1)
    sys.exit()
check = S[(firstblack+1):]
blacknum = check.count('#') # 黒の個数を返す
whitenum = check.count('#') # 白の個数を返す

if whitenum <= blacknum:
    print(whitenum)
else:
    print(blacknum)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = input()
S = input()

# 黒の右を黒に変える　or 黒を白にする
# 黒より右を全て黒にするか、黒を白にするか

if int(N) != len(S):
    print('桁数の不一致')
    sys.exit()
# for moji in S:
#     if ('.' or '#') != moji:
#         print('文字列が条件範囲外')
#         sys.exit()

# pattern 1:黒の右を全て黒
firstblack = S.find('#') # ない場合は-1を返す
check = S[(firstblack+1):]

blacknum = check.count('#') # 黒の個数を返す
whitenum = check.count('#') # 白の個数を返す

if whitenum <= blacknum:
    print(whitenum)
else:
    print(blacknum)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
c=0
for i in b:
    if i==".":
        c+=1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

left_black = 1 if S[0] == "#" else 0
right_white = S[1:].count(".") 
ans = left_black + right_white

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

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    n = int(input())
    s = input()
    ans = 0
    cnt = 0
    for i in range(n - 1, -1, -1):
        if (s[i] == '#'):
            ans += cnt
            cnt = 0
        else:
            cnt += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
#Left = white, Right = Black
n = int(input())
s = list(input())
ans = 10**9 + 7
black = s.count("#")
white = s.count(".")
tmp = []
#tmp[0] = "#", tmp[1] = "."
if s[0] == "#":
    tmp.append([1,0])
else:
    tmp.append([0,1])
"""
for i in range(1, n):
    if s[i] == "#":
        tmp.append([tmp[i-1][0] + 1, tmp[i-1][1]])
    else:
        tmp.append([tmp[i-1][0], tmp[i-1][1] + 1])
"""
for i in range(n):
    left = s[:i].count("#")
    right = s[i:].count(".")
    ans = min(ans, left + right)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
start = s[0]
pattern = []

prev = ''
b = 0
w = 0
for i in s:
    if (i == '#' and prev == '#') or (i == '#' and prev ==''):
        b += 1
    elif (i == '.' and prev == '.') or (i == '.' and prev == ''):
        w += 1
    elif i == '#':
        b += 1
        pattern.append(w)
        w = 0
    else:
        w += 1
        pattern.append(b)
        b = 0
    prev = i
    
if prev == '.':
    pattern.append(w)

if start == '.':
    pattern = pattern[1:]

totalw = 0
ans = 0
for i in range(len(pattern)):
    if i % 2 == 0:
        totalw += pattern[i]
    else:
        totalw -= pattern[i]
    ans = min(totalw, ans)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
start = s[0]
pattern = []

prev = ''
b = 0
w = 0
for i in s:
    if (i == '#' and prev == '#') or (i == '#' and prev ==''):
        b += 1
    elif (i == '.' and prev == '.') or (i == '.' and prev == ''):
        w += 1
    elif i == '#':
        b += 1
        pattern.append(w)
        w = 0
    else:
        w += 1
        pattern.append(b)
        b = 0
    prev = i
    
if prev == '.':
    pattern.append(w)

if start == '.':
    pattern = pattern[1:]
totalb = 0
totalw = 0
ans = 0
for i in range(len(pattern)):
    if i % 2 == 0:
        totalw += pattern[i]
    else:
        totalb += pattern[i]
    ans = min(totalw, totalb)
        
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

n = int(input())

lines = list(input())

ans_list = list()
for i in range(len(lines)):
    left = lines[:i].count('#')
    right = lines[i:].count('.')
    ans_list.append(left+right)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
n = int(input())

lines = list(input())

ans = n
for i in range(len(lines)):
    count = 0
    for j in range(len(lines)):
        if j <= i:
            if lines[j] == '#':
                count += 1
        else:
            if lines[j] == '.':
                count += 1
    if count < ans:
        ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
def solve(N, S):
    print(S)
    ans = [S.count('.')]
    for i in range(N):
        temp = ans[-1]
        temp += -1 if S[i] == '.' else 1
        ans.append(temp)
    return ans


# ... i / i+1 ####
# ####
N = int(input())
S = input()
print(min(solve(N, S)))

Submission status: Wrong Answer

Solution code:
def solve(N, S):
    if N <= 1:
        return 0

    W = [0]*N
    B = [0]*N
    W[0] = 1 if S[0] == '.' else 0
    for i in range(1, N):
        W[i] = W[i-1] + (1 if S[i] == '.' else 0)
    if W[-1] == 0 or W[-1] == N:  # all black/white
        return 0
    # print(W)
    ans = N+1
    for i in range(N-1):
        #print('left={}, right={}'.format(W[i], W[-1]-W[i]))
        left = i+1-W[i]
        right = W[-1]-W[i+1]
        #print(left, right)
        ans = min(ans, left+right)
    return ans

# ... i / i+1 ####
# ####
N = int(input())
S = input()
print(solve(N, S))

Submission status: Wrong Answer

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

cumsum_b = [0] * (N+1)
cumsum_w = [0] * (N+1)

cum_b = 0
cum_w = 0
for i in range(N):#累積和
  if S[i] == "#":
    cum_b += 1
  else:
    cum_w += 1
  cumsum_b[i+1] = cum_b
  cumsum_w[i+1] = cum_w
  
ans = N
for left in range(N):#白の範囲を全探索
  tmp = 0
  tmp += cumsum_b[left] - cumsum_b[0]#leftを白
  tmp += cumsum_w[-1] - cumsum_w[left]#rightを黒
  ans = min(ans,tmp)
else:
  print(ans)

Submission status: Wrong Answer

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

cumsum_b = [0] * (N+1)
cumsum_w = [0] * (N+1)


for i in range(N):#累積和
  if S[i] == "#":
    cumsum_b[i+1] = cumsum_b[i] + 1
    cumsum_w[i+1] = cumsum_w[i]
  else:
    cumsum_w[i+1] = cumsum_w[i] + 1
    cumsum_b[i+1] = cumsum_b[i]

ans = N
for left in range(N):#白の範囲を全探索
  tmp = 0
  tmp += cumsum_b[left] - cumsum_b[0]
  tmp += cumsum_w[-1] - cumsum_w[left]
  ans = min(ans,tmp)
else:
  print(ans)

Submission status: Wrong Answer

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

cumsum_b = [0] * (N+1)
cumsum_w = [0] * (N+1)


for i in range(N):#累積和
  if S[i] == "#":
    cumsum_b[i+1] += cumsum_b[i] + 1
    cumsum_w[i+1] += cumsum_w[i]
  else:
    cumsum_w[i+1] += cumsum_w[i] + 1
    cumsum_b[i+1] += cumsum_b[i]

ans = N
for left in range(N):#白の範囲を全探索
  tmp = 0
  tmp += cumsum_b[left] - cumsum_b[0]
  tmp += cumsum_w[-1] - cumsum_w[left]
  ans = min(ans,tmp)
else:
  print(ans)