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:
#!/usr/bin/env python3

# @date Time-stamp: <2019-04-20 22:14:10 tagashira>
# @file a.cpp
# @brief https://tenka1-2019-beginner.contest.atcoder.jp/tasks/tenka1_2019_c

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

# print(S.replace("#.","!!"))
output =0
for char in S.replace("#.","!"):
  if char == "!":
    output +=1

print(int(output))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
count1 = 0
count2 = 0
count = 0
counter = []

for i in range(N):
    if S[i] == '.':
        count2 += 1
        
for i in range(N-1):
    if S[i:i+2] == ['#','.']:
        count1 += 1
        if count:
            counter.append(count)
        count = 0
        S[i] = '.'
    elif S[i:i+2] == ['#', '#']:
        count += 1
    else:
        if count:
            counter.append(count)
        count = 0

for i in counter:
    count1 += i
    
print(min(count1, count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cntB = 0
cntW = 0

flg = S.find('#')

for j in range(N - flg):
    if S[flg + j] == '.':
        cntB += 1
    else:
        cntW += 1

print(min(cntB, cntW))

Submission status: Wrong Answer

Solution code:


def main():
    N = int(input())
    S = list(input())

    flg = 0
    ans = 0
    for i in range(N):
        if S[i] == '#':
            flg = 1
        if flg and S[i] == '.':
            ans += 1

    flg = 0
    ans_2 = 0
    for i in range(N)[::-1]:
        if S[i] == '.':
            flg = 1
        if flg and S[i] == '#':
            ans_2 += 1

    left = 0
    righ = N - 1
    ans_3 = 0
    while 1:
        while S[left] == '.':
            left += 1
            if left == N:
                break

        while S[righ] == '#':
            righ -= 1
            if righ == -1:
                break

        ans_3 += 2
        righ -= 1
        left += 1

        if left > righ:
            break

    if righ + 1 == left:
        pass
    else:
        ans_3 -= 2



    print(min(ans, ans_2, ans_3))




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

w_cnt = 0
w_list = []
b_cnt = 0
b_list = []
for i in range(N):
    if S[i] == '#':
        w_cnt += 1
        w_list.append(w_cnt)
    else:
        w_list.append(w_cnt)

    if S[N-1-i] == '.':
        b_cnt += 1
        b_list.append(b_cnt)
    else:
        b_list.append(b_cnt)
    


ans = N
for i in range(N):
    wa = w_list[i] + b_list[N-2-i]
    if ans > wa:
        ans = wa


if b_list[N-1] == 0 or w_list[N-1] == 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())

BLACK = '#'
WHITE = '.'

count1 = 0
for idx in range(len(S) - 1):
    if S[idx] == BLACK and S[idx + 1] == WHITE:
        if idx > 0 and S[idx - 1] == WHITE:
            S[idx] = WHITE
        else:
            S[idx + 1] = BLACK
        count1 += 1

count2 = 0
for idx in range(len(S) - 1):
    if S[idx] == BLACK:
        S[idx] = WHITE
        count2 += 1

print(min(count1, count2))

Submission status: Wrong Answer

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

left = stones.find("#")

if left == -1:
    print(0)
else:
    right = stones.rfind("#")
    stonesToChange = stones[left : right]
    print(min(stones[left:right].count("."), stones[left:].count("#")))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if len(set(S)) == 1:
    print(0)
    exit()

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
B,W =0,0
hoge = 0
flag = 0
for c in S:
    if c=="#":
        hoge+=1
        flag = 1
    if c == ".":
        if flag == 1:
            W += 1
        B += hoge
        hoge = 0
print(min(B,W))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
 
if s.count('.') == len(s):
    print(0)
else:
    s_ = s
    for i, wb in enumerate(s_):
        if wb == '.':
            s_ = s[i+1:]
        else:
            break
    
    ans_black_change = s_.count('#')
    if s[-1] == '#':
        ans_black_change -= 1
    ans_white_change = s_.count('.')
    
    ans = min(ans_black_change, ans_white_change)
    print(ans)

Submission status: Wrong Answer

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

d = 0
for i in range(n):
    if s[i] != ".":
        d = i
        break

    if i == n-1:
        d = i

count = 0
for j in range(n-d):
    if s[j+d] == "#":
        count += 1

print(min((count, n-d-count)))

Submission status: Wrong Answer

Solution code:
n = int(input())
raw = input()
start_idx = 0
count = 0

for s in raw:
    if s == '#':
        break
    start_idx = start_idx + 1

tmpb = 1
tmpw = 1
flg = '#'
reset = False
for i in range(start_idx, n):
    if reset:
        tmpb = 1
        tmpw = 1
        flg = '#'
        reset = False
    if flg == '#':
        if raw[i] == flg:
            tmpb = tmpb + 1
        else:
            flg = '.'
    else:
        if raw[i] == flg:
            tmpw = tmpw + 1
        else:
            reset = True
            if tmpb >= tmpw:
                count = count + tmpw
            else:
                count = count + tmpb

if tmpb >= tmpw:
    count = count + tmpw
else:
    count = count + tmpb


print(count)

Submission status: Wrong Answer

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

cnta = 0
la = l
cntb= 0
lb = l
for i in range(1, n):
    if (la[i-1] == "#")&(la[i-1] != la[i]):
        la[i] = "#"
        cnta += 1
if cnta ==0:
    cnta +=1

for i in range(0, n-1):
    if (l[i+1] == ".")&(l[i+1] != l[i]):
        l[i] = "."
        cntb += 1
if cntb ==0:
    cntb +=1

print(min(cnta, cntb))

Submission status: Wrong Answer

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

count = 0
for n in range(int(N)):
    if (S[n-1] == '#') & (S[n] == '.'):
        count = count+1

print(count)

Submission status: Wrong Answer

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

s = s.split('#')
print(len(s) - s.count(''))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
flag = 0
location1 = 0
location2 = n
for i in range(n):
    #    print(s[i])
    if s[i] == '#':
        location1 = i
        flag = 1
        break

i = 0

for i in range(n):
    #    print(s[n-i-1])
    if s[n-i-1] == '.':
        location2 = n - i - 1
        flag = 2
        break


if flag == 0:
    print(0)
else:
    print(min(s[location1:n].count('.'), s[0:location2].count('#')))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=s.count(".")
c=s.count("#")
ans=0
if s[0]=="#":
  print(min(a,c))
else:
  for i in range(n):
    if s[i]==".":
      ans+=1
    else:
      break
  print(min(a-ans,c))

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
scount=0
ccount=0
pp=0
ll=list()
for i in b:
        ll.append(i)
if "#" in ll:
        x=ll.index("#")
        y=ll.count(".")
        z=y-x
        q=ll.count("#")
        ccount=z
        
        for i in range(int(a)):
                scount-=1
                if ll[scount] == ".":
                        break
                else:
                        pp+=1
        if q-pp<z:
                ccount=q
                ccount-=pp
                
        
print(ccount)

Submission status: Wrong Answer

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

ans = 0
index = 0

another_ans = S.count("#")

if another_ans == 0:
    print(ans)
    exit()

for i in range(N):
    if S[N - 1 - i] == ".":
        index = N - 1 - i
        break

ans = S[:index].count("#")

if N - another_ans < ans:
    print(N - another_ans)
    exit()

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()

    try:
        first_black = s.index('#')
    except ValueError as e:
        print(0)
        exit(0)

    s2 = s[first_black+1:]
    print(s2.count('.'))

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
stemp=input()
s=[ i for i in stemp]

s2=copy.copy(s)
ans=0
ans2=0
ans3=0
f=0
for i in range(n):
    #print(i)
    if 1<=i and i<=n-1:
        if s[i]==".":
            ans+=1
    if i<=n-2:
        if s2[i]=="#":
            ans2+=1
    
    if n-i>0:
        if s[n-i-1]==".":
            f=1
    if n-i>0:
        if f:
            if s[n-i-1]=="#":
                ans3+=1
    #print(s[n-i-1], f, ans3)


#print(s)
#print(s2)
#print(ans,ans2,ans3)
if ans3!=0:
    print(min(ans,ans2, ans3))
else:
    print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
l=list(input())
m=0
b_ans=n
for i in range(len(l)-1):
    if (l[i]=="#" and l[i+1]=="."):
        b=l[m:].count(".")+l[:m].count("#")
        if(b<b_ans):
            b_ans=b
        #print(lm)

a=l.count("#")
c=l.count(".")
ans=min(a,b_ans,c)
print(ans)
#print(lm)

Submission status: Wrong Answer

Solution code:
n = int(input())

str = input()
count = 0

for i in range(n):
  if str[i] == "#":
    k = i
    for s in range(k,n):
      if str[s] == ".":
        count += 1
    break
    
count2 = 0
i = n-1
while i  >= 0:
  if str[i] == ".":
    k = i
    while k >= 0:
      if str[k] == "#":
        count2 += 1
      k -= 1
    break
  i -= 1

print(min(count,count2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=input()
B=True
if s=='.'*n:
    B=False
if B:
    num=list(s).index('#')
    if num!=n-1:
        for i in range(num,n-1):
            if s[i]=='.' and s[i+1]=='#':
                l=n-i-1
        moji=s[num:]
        moji+='.'
        lst=dict(Counter(moji).items())
        a=lst['#'];b=lst['.']
        if a==0 or b==1:
            print(0)
        else:
            if s[-1]=='#':
                print(min(a-l,b-1))
            else:
                print(min(a,b-1))
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

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

Bflag = False
count = 0
for i in range(N):
  if S[i] == '#':
    Bflag = True
  elif Bflag is True:
    count = count + 1
            
if count == 0:
  count = 1
print(count)

Submission status: Wrong Answer

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

if S.count("#") > S.count("."):
  print(S.count("."))
elif S.count(".") > S.count("#"):
  print(S.count("#"))
elif S.count("#") == 0 or S.count(".") == 0:
  print(0)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
import bisect

def main():
    N = int(input())
    S = list(input())
    # print(S)

    if S.count('.') == N or S.count('#') == N:
        print(0)
        exit()

    total_white = S.count('.')
    ans = total_white
    rest_white = total_white

    current_ans = 0
    S += '#'  # 番兵
    black_count = 0
    white_count = 0
    for i in range(len(S)):
        if S[i] == '#':
            black_count += 1
            if white_count > 0:
                # consider
                ans = min(ans, current_ans + white_count + rest_white)
                current_ans += (black_count - 1)
                white_count = 0
                black_count = 1
        else:
            if black_count > 0:
                white_count += 1
            # print('w')
            rest_white -= 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


from sys import stdin



############################################


# read data for n sequences.
n = stdin.readline()
N = int(n)
n = stdin.readline()
S = str(n)

#data = [int(stdin.readline().rstrip()) for _ in range(n)]

out=[]
count=0
for i,l in enumerate(S):
	if i < N:	
		if l == "#":
			count += 1

# count black on right
countX=0
for l in reversed(S):
	if l == "#":
		countX+=1
	else:
		break

countY=0
for l in S:
	if l == ".":
		countY+=1
	else:
		break
		
count2 = N-count-countY
count -= countX
print(min([count,count2]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
s = list(ns())
count = 0
lis = [0 for i in range(n)]
for i in range(len(s)):
    if s[i] == '.':
        count += 1
        lis[i] = count
    if s[i] == '#':
        count -= 1
        lis[i] = count
idx = lis.index(max(lis))
ans = s[:idx + 1].count('#') + s[idx + 1:].count('.')
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

# @date Time-stamp: <2019-04-20 22:12:39 tagashira>
# @file a.cpp
# @brief https://tenka1-2019-beginner.contest.atcoder.jp/tasks/tenka1_2019_c

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

# print(S.replace("#.","!!"))
output =0
for char in S.replace("#.","!!"):
  if char == "!":
    output +=1

print(int(output/2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def stones(s):
    a = s
    k = 0
    z = 0
    print(a)
    for i in range(len(s)-1):
        if s[i]=='#' and s[i+1]=='.':
            s[i+1] = '#'
            k = k+1
    for i in range(len(a)-1):
        if a[i]=='#' and a[i+1]=='.':
            a[i] = '.'
            z = z+1
    return min(z,k)

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

Submission status: Wrong Answer

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

prev = '.'
ans = 0

for i, s in enumerate(S):
    if s == '.' and prev == '#':
        ans += 1
    if prev == '.' and s == '#':
        prev = '#'

count_b = 0
for i, s in enumerate(S):
    if s == '#':
        count_b += 1

ans = min(count_b, ans)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li = []
i = 0
j = 0
cnt = 0
ans = 0
while i<n:
    while j<n and s[i]==s[j]:
        cnt += 1
        j += 1
    i = j
    li.append(cnt)
    cnt = 0

if s[0] == "#" and len(li)!=1:
    if n%2==0:
        a = sum(li[0::2])
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[-1]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
elif s[0] == "." and len(li)!=1:
    if n%2==0 and len(li)!=1:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2]) - li[0]
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
else:
    ans = 0

print(str(ans))

Submission status: Wrong Answer

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

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

if a != N and b != N:
    print(a if a <= b else b)
else:
    print(0)

Submission status: Wrong Answer

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

count_W = 0
for i, s in enumerate(S):
    if s == '#':
        count_W = S[i:].count('.')
        break

count_B = 0
for i in range(len(S)):
    if S[-(i + 1)] == '.':
        count_B = S[: -(i + 1)].count('#')
        break

print(min([count_W, count_B]))

Submission status: Wrong Answer

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

print(min(c,b,w))

Submission status: Wrong Answer

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

cnt=0
l = []
b = 1 if S[0] == "." else 0

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

if len(l)<=1:
    print("0")
    exit()

s = 0

for j in range(abs(b-1), len(l), 2):
    #print(j, l[j])
    s += l[j]

m = s
#print(s)
for j in range(b, len(l), 2):
    #print(j-2,l[j-2], j-1, l[j-1])
    if j-2 >= 0:
        s += l[j-2]-l[j-1]
    elif j-1 >= 0:
        s += -l[j-1]
    m = min(s, m)


#print(l)
print(m)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = list(input())
 
S_1 = copy.copy(S)
S_2 = copy.copy(S)
S_3 = copy.copy(S)
S_4 = copy.copy(S)
count_1 = 0
count_2 = 0
count_3 = 0
count_4 = 0

for i in range(N-1):
  if S_1[i] == "#" and S_1[i+1] == ".":
    S_1[i+1] = "#"
    count_1 += 1
    
#for i in range(N-1):
#  if S_2[i] == "#" and S_2[i+1] == ".":
#    S_2[i] = "."
#    count_2 += 1
    
for i in range(N-1):
  if S_3[N - i - 1] == "." and S_3[N - i - 2] == "#":
    S_3[N - i - 1] = "#"
    count_3 += 1
    
#for i in range(N-1):
#  if S_4[N - i - 1] == "." and S_4[N - i - 2] == "#":
#    S_4[N - i - 2] = "."
#    count_4 += 1
    
print(min(count_1, count_2, count_3, count_4))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=0
if s[0]=='.':
    a=0
    while s[a]=='.' and a!=n-1:
        a+=1
        ans+=1
for i in range(1,n):
    if s[i]=='.' and s[i-1]!='.' and i!=n-1:
        a=i+1
        while s[a]=='.' and a!=n-1:
            a+=1
            ans+=1
r=s.count('.')
if r==n:
    print(r-ans-1)
else:
    print(r-ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
count=[0]*n
for i in range(n):
    s1=s[:i-1]
    s2=s[i:]
    count[i]=s1.count('#')+s2.count('.')
print(min(count))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
lis = []
for i in range(1,n):
  if s[i-1] =="." and s[i] == "#":
    lis.append(s[:i:].count("#") + s[i::].count("."))
if len(lis) == 0:
  print(0)
else:
  lis.sort()
  print(lis[0])

Submission status: Wrong Answer

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

n = int(input())

s = list(input())

count = 0

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

        if s[i-1] == '#':
            s[i+1] = '#'
            count += 1
        elif s[i-1] == '.':
            s[i] = '.' 
            count += 1


print(count)

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]
    sharp=X.count("#")
    dot=X.count(".")+1
    print(min([sharp,dot])) 
except:
    print(0)

Submission status: Wrong Answer

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

fb = S.find('#')
fw = S_.find('.')

print(min(S[fb:].count('.'), S_[fw:].count('#')))

Submission status: Wrong Answer

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

sharp = 0
dot = 0
for string in s:
	if(string == "#"):
		sharp += 1
	else:
		dot += 1 

zend = len(s) - dot
if(s[len(s) -1] == "#"):
	zend -= 1

zens = len(s) - sharp
if(s[0] == "."):
	zens -= 1

sb = s.copy()

ans = 0

for i in range(len(s)-1):
	if(s[i] == "#" and s[i+1] == "."):
		if(i == 0):
			s[i] = "."
		elif(i > 0 and s[i-1] != "#"):
			s[i] = "."
		else:
			s[i+1] = "#"
		ans += 1

ansb = 0
for i in range(len(sb)-1):
	if(i == 0 and sb[i] != "."):
		sb[i] = "."
		ansb += 1
	elif(sb[i] == "#" and sb[i+1] == "."):
		if(i > 0 and sb[i-1] != "#"):
			sb[i] = "."
		else:
			sb[i+1] = "#"
		ansb += 1


#print(s)
#print(sb)


#print(ans)
#print(ansb)



ans = min(ans, ansb, zens, zend)

print(ans)

Submission status: Wrong Answer

Solution code:
import re
n = input()
N = int(n)

S = input()
# print(re.findall(r'\#*',S))

pattern = r'\#+|\.+'
repatter = re.compile(pattern)
result = repatter.findall(S)
# print(result)

pre = False
count = 0
ans = 0
for r in result[::-1]:
    if r[0] == '.':
        count = len(r)
        pre = True
    if r[0] == '#' and pre == True:
        tmpc = len(r)
        if count < tmpc:
            ans += count
        else:
            ans += tmpc
        pre = False
print(ans)

Submission status: Wrong Answer

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

count = 0

result1 = s.count('#')
result2 = s.count('.')


for x in s:
    count += 1
    if x != '.':
        break
    
    
result3 = s[count:].count('.')
result4 = s[count:].count('#') + 1


sorted(s,reverse = True)
count = 0

for x in s:
    count += 1
    if x != '#':
        break
    
result5 = s[count:].count('#')
result6 = s[count:].count('.') + 1
print(min(result1,result2,result3,result4,result5,result6))

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
a=0;X=0
while X<N:
  if X+1==N:
    break
  if S[X]=='#' and S[X+1]=='.':
    a+=1
    X+=2
  else:
    X+=1
print(a)

Submission status: Wrong Answer

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


def func(input_s):
    count = input_s.count(".")
    for c, i in enumerate(input_s):
        if c == "." and i != 0 and input_s[i - 1] == "#":
            tmp_str = input_s
            tmp_str[i - 1] = "."
            tmp_count = func(tmp_str[i:])
            count = min(tmp_count + 1, count)
        else:
            count -= 1
    return count


pre = ""
print(func(s))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10000000)


def check_and_back_or_go_to(li, ind, N, counter, white_charge):
    back = True
    # print('see {} {} and {} counter{}'.format(ind, li[ind - 1], li[ind], counter))
    if ind == 0:
        return counter

    # access
    if li[ind - 1] == '#' and li[ind] == '.':
        c = check_and_back_or_go_to(li, ind - 1, N, counter + 1 + white_charge, 0)
        return c
    elif li[ind - 1] == '.' and li[ind] == '.':
        return check_and_back_or_go_to(li, ind - 1, N, counter, white_charge + 1)
    else:
        c = check_and_back_or_go_to(li, ind - 1, N, counter, white_charge)
        return c


N = int(input())
S = list(input())
r = range(N)
if N == 1:
    print(0)
    exit(0)
bsk = False
key = -1
for i in range(len(S)):
    if not bsk:
        if S[i] == '#':
            bsk = True
            key = i
    else:
        if S[i] != '#':
            bsk = False

if bsk and key==0:
    print(0)
    exit(0)

if bsk:
    # print('bsk occured')
    # print([S[i] for i in range(key)])
    count = check_and_back_or_go_to([S[i] for i in range(key)], key  - 1, N, 0, 0)
    print(min([count, key - count]))
else:
    count = check_and_back_or_go_to(S, len(S) - 1, N, 0, 0)
    print(min([count, N - count]))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
x=0
for i in range(n-1):
  if s[i]=="#" and s[i+1]==".":
    x+=1
  elif s[i]=="#" and s[i+1]=="#":
    x+=1

y=0
for i in range(n-1):
  if s[n-1-i]=="." and s[n-2-i]=="#":
    y+=1
  elif s[n-1-i]=="." and s[n-2-i]==".":
    y+=1

if x<=y:
  print(x)
else:
  print(y)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
s = list(S)
if '#' in s:
  id = s.index('#')
  if id == N-1:
    print(0)
  elif s[id:N-1].count('.') == 0:
    print(0)
  else:
    a = s.count('#')
    b = s.count('.')
    if a > b:
      print(b)
    else:
      print(a)
else:
  print(0)

Submission status: Wrong Answer

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

bcounts = [0 for _ in range(len(S))]
wcounts = [0 for _ in range(len(S))]
cs = 0
for i in range(len(S)):
    if S[i] == '#':
        cs += 1
    bcounts[i] = cs
cs = 0
for i in reversed(range(len(S))):
    if S[i] == '.':
        cs += 1
    wcounts[i] = cs

INF = float('inf')
ans = INF
for i in range(len(S) - 1):
    if S[i] == '#' and S[i + 1] == '.':
        # 次の黒を超えたところの wcounts
        ni = i + 1
        while ni < len(S) and S[ni] == '.':
            ni += 1
        while ni < len(S) and S[ni] == '#':
            ni += 1
        wc = wcounts[ni] if ni < len(S) else 0
        ans = min(ans, bcounts[i] + wc)

print(0 if ans == INF else ans)
# たとえば ###.....##. は4が最適

Submission status: Wrong Answer

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

a = 0
b = 0

x = 0
y = 0

while x == 0 and y<N:
  if S[y] == '.':
    y += 1
  else:
    x = 1

if y+1 == N:
  print(0)
else:
  for i in range(y, N):
    if S[i] == '.':
      a += 1
    else:
      b += 1
  print(min(a, b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

str = input()
count = 0

for i in range(n):
  if str[i] == "#":
    k = i
    for s in range(k,n):
      if str[s] == ".":
        count += 1
    break
    
count2 = 0
i = n-1
while i  >= 0:
  if str[i] == ".":
    k = i
    while k >= 0:
      if str[k] == ".":
        count2 += 1
      k -= 1
    break
  i -= 1

print(min(count,count2))

Submission status: Wrong Answer

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

from sys import stdin
    
def calc(n, s):
    s2 = [ c == '#' for c in s]
    total = sum(s2)
    _min = min(total, n-total)
    tr = 0
    for i,c in enumerate(s2):
        if c:
            tr += 1
        op = 2*tr+n-(i+1)-total
        if op < _min:
            _min = op
        else:
            break

    return _min

def main():
    n = int(stdin.readline().rstrip())
    s = stdin.readline().rstrip()
    ans = calc(n, s)
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

c=0
b=0
w=0
res=0
for i in range(n-1):
	if sl[i]=="#":
		b=b+1
	else:
		b=0

	if sl[i]=="#" and sl[i+1]==".":
		for j in range(1, n-i):
			if sl[i+j]==".":
				w=w+1
			else:
				break
		if b <= w:
			res=res+b
			b=0
			w=0
		else:
			res=res+w
			b=b+w
			w=0
print(res)

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline())
s = sys.stdin.readline()

bcnt = 0
wcnt = 0
bst = -1
lastlen = 0

for i in range(n):
    tmp = s[i:i + 1]
    if "#" in tmp:
        bcnt += 1
        if bst == -1:
            bst = i
        lastlen += 1
    elif "." in tmp:
        if bst >= 0:
            wcnt += 1
        lastlen = 0

print(min(wcnt, bcnt-lastlen))

Submission status: Wrong Answer

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

ans = 0
s_count = 0
if len(S) == 1:
    print(ans)
elif len(S) == 2:
    if S == ['#', '.']:
        print("1")
    else:
        print("0")
elif len(S) == 3:
    for i in range(len(S)-1):
        if S[i] == '#' and S[i+1] == '.':
            ans += 1
    print(ans)
            
else:
    for c in S:
        if c=='#':
            s_count += 1
    for i in range(1, len(S)-2):
        if S[i] == '#' and S[i+1] == '.':
            if S[i+2] == '.':
                if S[i-1] == '.':
                   S[i] = '.'
                if S[i-1] == '#':
                    S[i+1] = '#'
            else:
                S[i+1] = '#'
            ans += 1
            
    if S[-2:] == ['#', '.']: # -> ##
        ans += 1
    if S[:2] == ['#', '.']: # -> ..
        ans += 1

    print(min(s_count, ans, len(S)-s_count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
# . = しろ
# # = 黒
# #の横に.がないようにしたい
# #の横に.があったら#を.に変える
# or #の横に.があったら.を#に変える

# when do you replace now char to .
# 

# テストケース
"""
9
.#.#.#.#.
"""
# => .....# = 2

def inorderReplace(S , N): 
    S = list(S)
    cnt = 0
    for i in range(N - 1) : 
        nowChar = S[i]
        nextChar = S[i + 1]
        if nowChar == "#" and nextChar == "." : 
            cnt += 1
            S[i + 1] = "#"
    return cnt

def calcCount(S , N) : 
    countingChar = S[0]
    rst = []
    count = 1
    for s in S[1:] :
        if countingChar == s : 
            count += 1
        else : 
            rst.append((countingChar , count))
            count = 1
            countingChar = s
    rst.append((countingChar , count))
    return rst

def countRightChange(countingList) : 
    #全部を.に変えるコスト
    cnt = 0
    for elem in countingList : 
        if elem[0] == "#" : 
            cnt += elem[1]
    return cnt

def countLeftChange(countingList) : 
    # 全部を#に変えるコスト
    cnt = 0
    for elem in countingList : 
        if elem[0] == "." : 
            cnt += elem[1]
    return cnt

def calcPoint(countingList) : 
    minVal = float('inf')
    a = 0
    b = countLeftChange(countingList)
    for i in range(len(countingList)) : 
        elem = countingList[i]
        if elem[0] == "." : 
            a += 0
            b -= elem[1]
        elif elem[0] == "#" : 
            a += elem[1]
            b -= 0
        if minVal > a + b : 
            minVal = a + b
    return minVal




#cnt = inorderReplace(S , N)
countingList = calcCount(S , N)
cnt2 = calcPoint(countingList)

print(cnt2)

Submission status: Wrong Answer

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

S = list(S)
white = S.copy()
black = S.copy()
ans1 = 0
ans2 = 0
# for i in range(N):
#     if i+1 < N:
#         if white[i] == '#' and white[i+1] == '.':
#             white[i+1] = '#'
#             ans1 += 1

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



# flag = 0
# flag = S.count('#')
# if flag > 0:
#     ans = S.count('.')
last_white = 0
last_white_flag = False
for i in range(N):
    if white[i] == '.':
        last_white_flag = True
        last_white = i
S = S[:last_white+1]
# print(S)
ans1 = S[:last_white+1].count('#')
ans2 = S.count('.')

# print(S)
# print(ans1)
# print(ans2)
if ans1 < ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(str(input()))
w=0
b=0
wl=[]
bl=[]
for i in range(n):
    if s[i]==".":
        w+=1
    else:
        b+=1
    wl.append(w)
    bl.append(b)
if "#" not in s or "." not in s:
    print(0)
elif s.count(".")==1:
    print(1)
else:
    ans=[]
    for i in range(n):
        ans.append(bl[i]+wl[-1]-wl[i])
    print(min(ans))