Problem:


Score : 300 points

Problem Statement

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
#.#

Sample Output 1

1

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

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
w_num = 0
b_num = 0

for i in range(n):
    if s[i] == '.':
        w_num += 1
    else:
        b_num += 1

print(w_num if w_num < b_num else b_num)

Submission status: Wrong Answer

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

trial_num = int(input())
stones = list(input())

min_turn_stones = 2*10**5

black_stones = stones.count("#")
white_stones = trial_num - black_stones

for i in range(trial_num):
    tmp_black_stones = stones[:i+1].count("#")
    tmp_min = 2*tmp_black_stones + (trial_num-1-i) - black_stones
    if(tmp_min < min_turn_stones):
        min_turn_stones = tmp_min

print(min_turn_stones)

Submission status: Wrong Answer

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

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

print(x)

Submission status: Wrong Answer

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

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

s1='.'*n
s2='#'*n
if n==1:
    ans=0
else:
    if fb==-1:
        ans=0
    else:
        s3='.'*fb+'#'*(n-fb)
        x=0
        y=0
        z=0
        for i in range(n):
            if s1[i]!=s[i]:
                x+=1
            if s2[i]!=s[i]:
                y+=1
            if s3[i]!=s[i]:
                z+=1
        ans=min(x,y,z)
print(ans)

Submission status: Wrong Answer

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

black_start = s.find("#")
black_end = s.rfind("#")

white_start = s[black_start:].find(".")
white_end = s[black_start:].rfind(".")

black = s[black_start:].count("#")
white = s[black_start:].count(".")

if black == 0 or white ==0:
    print(0)
else:
    if (white_end - white_start +1) == s[white_start:white_end+1].count(".") and white_end < black_end :
        print(1)
    else:
        print(min(black, white))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = [0,0] #[# .]
i=0
l=0

while(i<n and s[i] == "."):
	i+=1
while(i<l and s[-l-1] == "#"):
	l+=1
for j in range(i,n-l-1):
	cnt[s[j] == "."] += 1
print(min(cnt))

Submission status: Wrong Answer

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

for i in range(N):
    if S[i]=='#':
        break
B = S[i:].count('#')
W = S[i:].count('.')
if B<W:
    ans = B
    if S[-1]=="#":
        ans -= 1
else:
    ans = W
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
i = 0
b = 0
w = 0

while i < n:
    if s[i:i+1] == '#':
        b += 0
        i += 1
        while i < n:
            if s[i:i+1] == '#':
                b += 1
            else:
                w += 1
            i += 1
    else:
        i += 1

print(min([b, w]))

Submission status: Wrong Answer

Solution code:
input()
S = [1 if v == "." else 0 for v in input()]

count = 0
for s in S:
    if s == 0:
        break
    count += 1

print(sum(S) - count)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    S = str(input())

    sharp_place = S.find("#")

    if sharp_place == -1:
        ok_pattern1 = "."*N
    else:
        ok_pattern1 = "."*sharp_place + "#" * (N-sharp_place)

    answer1 = 0

    for j in range(0, len(ok_pattern1)):
        if ok_pattern1[j] != S[j]:
            answer1 += 1

    answer2 = S.count("#")

    answer = min(answer1, answer2)

    print(answer)

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<z:
                ccount=q
                ccount-=pp
                
        
print(ccount)

Submission status: Wrong Answer

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

ans = 0
cnt_black = 0
cnt_white = 0
sakaime = False
for idx in range(n):
    if not sakaime:
        if s[idx] == '#':
            cnt_black += 1
            if cnt_white >= 1:
                cnt_white = 0
        elif s[idx] == '.':
            cnt_white += 1

        if idx >= 1:
            # print(s[idx-1:idx+1], ans)
            if s[idx-1:idx+1] == '#.':
                sakaime = True

    else:
        if s[idx] == '.':
            cnt_white += 1
        elif s[idx] == '#':
            ans += min(cnt_black, cnt_white)
            cnt_black = 1
            cnt_white = 0
            sakaime = False

if s[-1] == '.':
    ans += min(cnt_black, cnt_white)

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(result1,result2,result3,result4,result5,result6)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
s = 0
l = N - 1
while s < N and S[s] == ".":
    s += 1
while l >= 0 and S[l] == "#":
    l -= 1
if s >= l:
    print(0)
    exit()
ans = min(S[s:l+1].count("."), S[s:l+1].count("#"), S.count("."), S.count("#"))
print(ans)

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 += 13


print(count)

Submission status: Wrong Answer

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

if n == 1:
    print(0)
else:
    siro = s.count(".")
    kuro = n-siro
    if siro > kuro:
        for i in range(1,n):
            if s[i-1] =="#" and s[i] == ".":
                counter += 1
    elif kuro > siro:
        for i in range(n-1):
            if s[i] =="#" and s[i+1] == ".":
                counter +=1
                
    print(counter)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
h=0
b=0
for i in range(len(s)):
    if s[i]=="#":
        b+=1
    if s[i]=="." and b!=0:
        h+=1
b2=0
h2=0
for i in range(len(s)-1,-1,-1):
    if s[i]=="#" and h2!=0:
        b2+=1
    if s[i]==".":
        h2+=1

print(min(h,b2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sharp = 0
dot = 0
for i in s:
    if i == "#":
        sharp += 1
    if i == ".":
         dot += 1
print(min(sharp, dot))

Submission status: Wrong Answer

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

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(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:
input()
s=input()
print(min(s.count("#"),s.count(".")))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = list(input())
    
    arr = []
    cnt = 1
    for i in range(1, n):
        if s[i] == s[i - 1]:
            cnt += 1
        else:
            arr.append(cnt)
            cnt = 1
    arr.append(cnt)
    
    if s[0] == '.':
        arr = [0] + arr
    if s[-1] == '#':
        arr += [0]
    
    for i in range(len(arr) - 3, -1, -2):
        arr[i] += arr[i + 2]
    for i in range(2, len(arr), 2):
        arr[i] += arr[i - 2]
    
    arr += [0, 0]
    
    ans = n
    for i in range(1, len(arr) - 2, 2):
        ans = min(ans, arr[i - 1] + arr[i + 2])
    
    print(ans)
    return 0

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c1 = 0
for i in range(N - 1, -1, -1):
    if S[i] == ".":
        c1 = i
        break
c2 = N - 1
for i in range(N - 1, -1, -1):
    if S[i] == '#':
        c2 = i
        break
a = S[:c2 + 1].count('#') + S[c2:].count('.')
b = S.count("#")
c = S.count(".")
ans = min(a, b, c)
print(ans)

Submission status: Wrong Answer

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

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

first = 0
position = 0
secondposition = 0
count2 = 0
for i in reversed(range(n)):
    if(first == 0 and s[i] == '#'):
        first += 1
        position = i+1
    if(first == 1 and s[i] == '.'):
        secondposition = i+1
        break;
if(position == 0):
    print(0)
elif(secondposition == 0):
    print(min(n-position,position))
else:
    for j in range(secondposition-1):
        if(s[j] == '#'):
            count2 += 1

    count1 = n - position

    ans1 = count1 + count2
    print(ans1)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
flag=0
countB=0
countB2=0
for i in range(N):
  if S[i]=="#":
    if flag==0:
      NNum=i
      flag=1
    countB += 1
    countB2+=1
  else:
    countB2=0
if flag==1:
  countW=N-NNum-countB
  countB=countB-countB2
  if countB>countW:
    print(countW)
  else:
    print(countB)
else:
  print(0)

Submission status: Wrong Answer

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

count = 0
while(1):
  if((count == N)or(len(S) == 0)):
    break
  if(S[0] == '.'):
    S.pop(0)
  if((count == N)or(len(S) == 0)):
    break
  if(S[-1] == '#'):
    S.pop(-1)
  count += 1

T = S.copy()
ans1,ans2,ans3 = 0,0,0
for i in range(len(S)):
  if(i != 0):
    if((S[i-1] == '#')and(S[i] == '.')):
      ans1 += 1
      S[i] = '#'
  if(T[i] == '#'):ans2 += 1
  if(T[i] == '.'):ans3 += 1
ans = min(ans1,ans2,ans3)
print(ans)

Submission status: Wrong Answer

Solution code:
num = int(input())
a = input()
a = list(a)
b = a.count(".")
c = a.count("#")
count = 0
for i in range(num):
  if b <= c:
    if i <= num-2 and a[i] == "#" and a[i+1] == ".":
      count += 1
      a[i+1] = "#"
  else:
    if i <= num-2 and a[i] == "#" and a[i+1] == ".":
      count += 1
      a[i] = "."
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
a = 0
b = 0
flag = 0
for i in range(len(s)):
    if flag == 0:
        if s[i] == '#':
            if i != 0:
                ans += min(a,b)
                if a < b:
                    flag = 1
                a = 0
                b = 0
            a += 1
        if s[i] == '.':
            b += 1
            if i == len(s) -1:
                ans += min(a,b)
    if flag == 1:
        ans += s[i+1:].count('.')
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

zeros = ["." for i in range(N)]
ones = ["#" for i in range(N)]
lastone = ["." for i in range(N - 1)]
lastone.append("#")
firstzero = ["#" for i in range(N - 1)]
firstzero.insert(0, ".")
count = 0
z = 0
o = 0
l = 0
f = 0

for i in range(N - 1):
    if S[i] != S[i + 1]:
        count += 1

if (count == 0 or (S[0] == "." and count == 1)):
    print(0)
    sys.exit()        

for i in range(N):
    if S[i] != zeros[i]:
        z += 1

for i in range(N):
    if S[i] != ones[i]:
        o += 1

for i in range(N):
    if S[i] != lastone[i]:
        l += 1

for i in range(N):
    if S[i] != firstzero[i]:
        f += 1

print(min([z, o, l, f]))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
new_S = ""
for i in reversed(S):
    new_S += i

for i in range(N):
    if new_S[i] == ".":
        S_new = S[i:]
        break
else:
    S_new = ""

print(min(S_new.count('#'), S_new.count('.'), len(S_new)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = str(input())
# ".": 白
# "#": 黒
# 黒い石のすぐ右に白い石があるような箇所がないように

now = "."
encoded = []
if S[0] == "#":
    S = "." + S
#Sは "." からスタート
tmp = 0
for i in S:
    if i == now:
        tmp = tmp + 1
    else:
        encoded.append(tmp)
        if now == ".":
            now = "#"
        else:
            now = "."
        tmp = 1
encoded.append(tmp)
ans = 0
for i in range((len(encoded)-1)//2):
    idx = 2 * i +1
    ans = ans + min(encoded[idx], encoded[idx+1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input()) 
s = list(input().split('.'))

num = [i.count('#') for i in s[:-1]]
m = sum(num)
if m == n:
    m = 0
print(m)

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

print(count1)

Submission status: Wrong Answer

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

d = []

s = S[0]
c = 1
for i in range(1,N):
    if s == S[i]:
        c += 1
    else:
        d.append(c)
        c = 1
        s = S[i]
d.append(c)
ans = 0
if S[-1] == "#":
    for i in range(2,len(d),2):
        ans += min(d[-i],d[-i-1])
else:
    for i in range(1,len(d),2):
        ans += min(d[-i],d[-i-1])
print(ans)

Submission status: Wrong Answer

Solution code:
def stones(s):
    a = s
    k = 0
    z = 0
    c = s.count('#')
    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-1] = '.'
            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()
s1 = s
a = 0
b = 0
for i in range(n-1):
  while s[i] == "#" and s[i+1] == "." :
    s = s.replace(s[i+1],"#")
    a += 1
  s = s1
  while s[i] == "#" and s[i+1] == "." :
    s = s.replace(s[i],".")
    b += 1
print(min(a,b))

Submission status: Wrong Answer

Solution code:
n = int(input())
sk = list(input())
target = sk[:]

for i,e in enumerate(sk):
    if e == '.':
        target = target[1:]
    else:
        break

target2 = target[:]

for i,e in enumerate(reversed(target)):
    if e == '#':
       target = target2[:-1]
    else:
        break

#print(n,target2)

result = target2
if len(result) == 0:
    print(0)
    exit(0)

cntA =0
cntB =0
for e in target2:
    if e == '.':
        cntA += 1
    else:
        cntB += 1

print(min(cntA,cntB))

#print(''.join(target))

Submission status: Wrong Answer

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


black_count = 0
white_count = 0
right_white_pos=-1
for i in range(N):
    if(S[i]=="."):
        white_count+=1
        right_white_pos=i
    else:
        black_count+=1

counter = 0
for i in range(N):
    if(i<right_white_pos):
        if(S[i]=="#"):
            counter +=1


S_black_list=list(S)

to_black_counter=0
for i in range(N-1):
    if(S_black_list[i]=="#" and S_black_list[i+1]=="."):
        to_black_counter+=1
        S_black_list[i+1]="#"

#print(white_count)
#print(black_count)
#print(counter)
#print(to_black_counter)
print(int(min(white_count, black_count, counter, to_black_counter)))


'''
black_count = 0
white_count = 0
right_white_pos=-1
for i in range(N):
    if(S[i]=="."):
        white_count+=1
        right_white_pos=i
    else:
        black_count+=1

S_black_list=list(S)

to_black_counter=0
for i in range(N-1):
    if(S_black_list[i]=="#" and S_black_list[i+1]=="."):
        to_black_counter+=1
        S_black_list[i+1]="#"


        

#print(white_count)
#print(black_count)
#print(to_black_counter)
print(min(white_count, black_count, to_black_counter))
'''

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
c=0
d=0
for i in range(0,N,1):
  if S[i]=="#":
    moji=S[i:]
    c=moji.count(".")
    d=moji.count("#")
    break

if c<=d:
  print(c)
elif c>d:
  print(d)

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

print(x-1)

Submission status: Wrong Answer

Solution code:
N = int(input())+1
S = '.' + input()
b,w,flg,ans,w_b = 0,0,0,0,0
for i in range(N):
  if S[-i+1] == '.':
    if flg == 0:
      w += 1
      flg = 1
    elif flg == 1:
      w +=1
    elif flg == 2:
      if b+w_b < w:
        ans += w
        w_b += b+w
      else:
        ans += b
      b,w = 0,1
      flg = 1
  elif flg == 1:
    b+=1
    flg = 2
  elif flg == 2:
    b+=1
print(ans)

Submission status: Wrong Answer

Solution code:
_ = int(input())

print(input().count("#."))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
b = [0]*(n)
w = [0]*(n)
if n == 1:
    print(0)
    exit()
if s[0] ==".":
    w[0] =1
else:
    b[0] =1
for i in range(1,n):
    if s[i] == ".":
        w[i] = w[i-1] + 1
        b[i] =b[i-1]
    else:
        b[i] = b[i-1] + 1
        w[i] = w[i-1]
ans = n
for j in range(n):
    ans = min(ans,b[j]+w[n-1]-w[j])
print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
S=list(map(str,input()))
#blcok to white
b_index_num = [n for n,v in enumerate(S) if v =='#' and n!=len(S)-1]

#white to block
w_index_num = [n for n,v in enumerate(S) if v =='.' and n!=0]
print(min([len(b_index_num),len(w_index_num)]))

Submission status: Wrong Answer

Solution code:
"""
python3 a.py < input.txt
"""
import math
import itertools as it
import heapq

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

s=[si for si in S]
nb=0
prev=S[0]
for i in range(1,N):
    if s[i-1]=="#" and s[i]==".":
        nb=nb+1
        s[i]="#"

s=[si for si in S]
nw=0
prev=S[-1]
for i in reversed(range(1,N)):
    if s[i]=="." and s[i-1]=="#":
        nw=nw+1
        s[i-1]="."
print(min(nb, nw))

Submission status: Wrong Answer

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

a = s.count("#")
b = s.count(".")

print(min(a, b))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
for i, s in enumerate(S.split("#")):
     if i == 0:
         continue
     else:
         count += s.count(".")
if count < S.count("#"):
    count = S.count("#")
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt1 = 0
cnt2 = 0
S1 = S
S2 = S
for i in range(1, N):
  if S1[i-1] == "#" and S1[i] == ".":
    S1 = S1.replace(S1[i-1], ".", 1)
    cnt1 += 1
for i in range(1, N):
  if S2[i-1] == "#" and S2[i] == ".":
    S2 = S2.replace(S2[i-1], "#", 1)
    cnt2 += 1
  
print(min(cnt1,cnt2))

Submission status: Wrong Answer

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

while len(s) > 0 and s[0] == '.':
    s = s[1:]
while len(s) > 1 and s[-1] == '#':
    s = s[:-1]

b, w = 0, 0
for c in s:
    if c == '.':
        w += 1
    else:
        b += 1
print(min(b, w))

Submission status: Wrong Answer

Solution code:
import sys
import math
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N = ni()
S = ns()

#最初のBが出てくるまでを数える
fastB = False
fastW = False
secondB=False
w0,w1,b0,b1 = 0,0,0,0

for s in S:
    if(s=="."):
        #print("w")
        if(fastB and fastW):
            secondB=True
            w1+=1
        else:
            fastW=True
            w0+=1
    elif(s=="#"):
        #print("b")
        if(fastB and fastW and secondB):
            b1+=1
        else:
            fastB=True
            fastW=True
            b0+=1
w=True
res=0
for s in S[::-1]:
    if(s=="#"):
        if(w):
            res+=1
        else:
            break
    else:
        w=False
w=True
resw=0
for s in S[::-1]:
    if(s=="."):
        if(w):
            resw+=1
        else:
            break
    else:
        w=False


#print(b0+b1,w0+w1,w1)
#print(b0,b1,w0,w1)

print(min(b0+b1-res,w1))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().rstrip()
index = S.find("#")
answer = 10**9
if index == -1:
    print(0)
    exit()
else:
    answer = S[index:].count(".")
index = S.rfind(".")
if index == -1:
    print(0)
    exit()
else:
    answer = S[:index+1].count("#") if S[:index+1].count("#")<answer else answer
index_s = S.rfind("#")
S_new1 = S[:index_s]
S_new1 = S[:S_new1.rfind(".")+1]
S_new2 = S[index-1:]
res = S_new2.count(".") + S_new1.count("#")
answer = res if res < answer else answer
print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
left=0
right=0
i=0

if s.count('.')==n:
  ans=0
else:
  while s[i]=='.':
    i+=1
    cnt+=1
#print(cnt)
  
s=s[cnt:]
ans=s.count('.') 

if s.count('.')==n:
  ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s1 = '#'
i = 0
slis = []
ini = True

for s in S:
  if s == s1:
    i += 1
  if s != s1:
    if ini:
      slis.append(i)
      ini = False
    else:
      slis.append(i + 1)
    s1 = s
    i = 0

slis.append(i+1)

if S.startswith('.'):
  slis = slis[2:]

if S.endswith('#'):
  slis = slis[:-1]

sum1 = sum(slis[0::2])
sum2 = sum(slis[1::2])

print(min(sum1, sum2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=0
flg=False

for i in range(N):
    if flg == False:
      if S[i] == '#':
          flg = True
          P = i
      else:
        continue

    if S[P] == S[i] :
        continue
    else:
        count +=1

if count <= (N / 2):
    print(count)
else:
    print(N - count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
mini = N
for i in range(0,N-1):
  white = S[0:i+1].count('#')
  black = S[i+1:N].count('.')
  sc = white + black
  if sc < mini:
    mini = sc
print(mini)

Submission status: Wrong Answer

Solution code:
def dif(string, ch):
    res = 0
    for i in range(len(string)):
        if string[i] != ch:
            res+=1
    return res

n = int(input())
string = input()

min = n
for i in range(n+1):
    m = dif(string[:i],"#") + dif(string[i:],".")
    if m < min:
        min = m

print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
w = 0
b = 0
for si in input():
    if si == '.':
        w += 1
    else:
        b += 1
print(min(w, b))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if N == 1:
    print("0")
    exit()
for i in range(N-1):
    if S[i] == "." and S[i+1] == "#":
        break
sharp_count = 0
for j in range(i+1,N):
    if S[j] == "#":
        sharp_count += 1

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

dot_count = 0
for j in range(index,N):
    if S[j] == "#":
        dot_count += 1

dot_count += S[:index].count(".#")
        
print(min(sharp_count,dot_count, S.count(".#")))

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+1
        break

    if i == n-1:
        d = i+1

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:
def main(word):
    strs = list(word)

    if strs.count('#') < strs.count('.'):
        return strs.count('#')

    count = 0
    iRegular = False
    for i, _ in enumerate(strs):
        if i == 0:
            continue
        if strs[i-1] == "#" and strs[i] == ".":
            count += 1
            continue

        if i < 2:
            continue
        if iRegular and strs == ".":
            count += 1
            continue
        else:
            iRegular = False
        if strs[i-2] == "#" and strs[i-1] == "." and strs[i] == ".":
            iRegular = True
            count += 1

    return count


if __name__ == "__main__":
    input()
    word = input()
    print(main(word))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
right = []
left = []
cnt = [0 for x in range(N)]
for x,y,z in zip(S[:N:],S[1::],range(N)):
    if x == '#' and y == '.':
        cnt[z] = 1
        right.append(z)
    elif x == '.' and y == '#':
        cnt[z] = -1
        left.append(z)
left.append(N-1)
try:
    if right[0]>left[0]:
        left.pop(0)
except:
    pass
for x,y in zip(right,left):
    ans += y-x
print(min(ans,N-ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
SS = list(S)
 
D = 0
 
black = S.split("#")
white = S.split(".")
if len(SS) ==0:
  while SS[0] == ".":
    white.pop(0)
    SS.pop(0)
    if len(SS) ==0:
      break
if len(SS) ==0:    
  while SS[len(SS)-1] == "#":
    black.pop()
    SS.pop()
    if len(SS) ==0:
      break
    
while "" in black:
  black.remove("")
  
while "" in white:
  white.remove("")
  
for b, i in zip(black,white):
  D += min(len(b),len(i))
  
print(D)

Submission status: Wrong Answer

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    s = lines[1]

    return (n, s)


def solve(n, s):
    
    ss = []
    for c in s:
        if c == ".":
            ss.append(True)
        else:
            ss.append(False)

    len_ss = len(ss)
    result = 0
    if len_ss == 1:
        result = 0
    elif len_ss == 2:
        if ss == [False, True]:
            result = 1
    elif len_ss == 3:
        if ss == [True, True, True]:
            pass
        if ss == [True, True, False]:
            pass
        if ss == [True, False, True]:
            result = result + 1
        if ss == [False, True, True]:
            result = result + 1
        if ss == [True, False, False]:
            pass
        if ss == [False, True, False]:
            result = result + 1
        if ss == [False, False, True]:
            result = result + 1
        if ss == [False, False, False]:
            pass
    else:
        result = 0
        for i, d in enumerate(ss):
            if i > 0 and ss[i-1] is True and ss[i] is False and i+1 < len_ss and ss[i+1] is True:
                ss[i] = True
                result = result + 1
            if i > 0 and ss[i-1] is False and ss[i] is True and i+1 < len_ss and ss[i+1] is True:
                ss[i-1] = True
                result = result + 1
            if i > 0 and ss[i-1] is False and ss[i] is True and i+1 < len_ss and ss[i+1] is False:
                ss[i] = False
                result = result + 1
            if i > 0 and ss[i-1] is False and ss[i] is False and i+1 < len_ss and ss[i+1] is True:
                ss[i+1] = False
                result = result + 1
        

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

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

num_black = S.count('#')
num_white = S.count('.')

S_1 = S.copy()

cnt_n = 0
cnt_r = 0
prev_n = S[0]
prev_r = S_1[0]

for i in range(1, len(S)):
    if prev_n == '#' and S[i] == '.':
        S[i] = '#'
        cnt_n += 1
    if prev_r == '#' and S_1[i] == '.':
        cnt_r += 1
    prev_n = S[i]
    prev_r = S_1[i]

print(min([cnt_n, cnt_r]))

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
tmp = S.count('.')
tmp_1 = S.count('#')
if S[0] == '.':
    counter = 0
    count = 0
    while count < len(S) and S[count] != '#':
        counter += 1
        count += 1
    tmp -= counter 
if S[0] == '#':
    counter = 0
    count = 0
    while count < len(S) and S[count] != '.':
        counter += 1
        count += 1
    tmp_1 -= counter 
print(min(tmp, tmp_1))

Submission status: Wrong Answer

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")


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

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


i = S.find('#.')
a = S[(i+1):]
p(i, a)

while i>=0:
	j = S.find('#.',i+1)
	if j==-1: break
	i=j

b = S[:(i+1)]
p(i, b)

ans = min(a.count('.'), b.count('#'))
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=0
b=0
for i in range(n):
    if s[i]=='.':
        a=a+1
    else:
        b=b+1
if a>b and s[n-1]=='#':
    print(a-1)
else:
    print(min(a,b))

Submission status: Wrong Answer

Solution code:
N = int(input())
s=list(input())
ii = 9999999999
count_a = 0
count_b = 1
count_c = 0
for index, i in enumerate(s):
  if i == '#' and ii == 9999999999:
    ii = index
    continue;
  elif ii == 9999999999:
    continue;
  else:
    if i == '.':
      count_a+=1
      count_c=0
    else:
      if index != N-1:
        count_b+=1
        count_c+=1
print(min(count_a, count_b-count_c))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
T = S
#print(S)
ans = 0
hens = 0
for j in range(N-1):
    if S[j] == "#" and S[j+1] == ".":
        ans += 1
        S = S.replace(".", "#", j+1)

for k in range(N-1):
    if T[-k-1] == "." and T[-k-2] == "#":
        hens += 1
        T = T.replace("#",".",-k-2)
print(min(ans, hens))