Problem:


Score : 300 points

Problem Statement

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
#.#

Sample Output 1

1

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

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

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

SLFront = list(S)
SLRear = list(S)

#print(SLFront)
countF = 0
for i in range(len(SLFront)-1):
	if SLFront[i] == "#" and SLFront[i+1] == ".":
		SLFront[i] = "."
		countF += 1
		
#print(countF,SLFront)

#print(SLRear)
countR = 0
for i in range(len(SLRear)-1):
	if SLRear[i] == "#" and SLRear[i+1] == ".":
		SLRear[i+1] = "#"
		countR += 1
		
#print(countR,SLRear)

print(min(countF,countR))

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
    elif ind + 1 == N:
        back = False
    # access
    if li[ind - 1] == '#' and li[ind] == '.':
        if back:
            c = check_and_back_or_go_to(li, ind - 1, N, counter + 1 + white_charge, 0)
            return c
        c = check_and_back_or_go_to(li, ind - 1, N, counter + 1, white_charge)
        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 len(S)==1:
    print('0')
    exit(0)
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:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math,string
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S = read_str()

def solve():
    ans = 0
    head_dot = 0
    tail_hash = N
    for i in range(N):
        if S[i] != ".":
            break
        head_dot += 1
    for i in range(N):
        if S[N - i -1] != "#":
            break
        tail_hash -= 1

    ans = min(S[head_dot:tail_hash].count("."), S[head_dot:tail_hash].count("#"))
    return ans

if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
#" . #
#  b=black#
#  w=white.
f=[0,1][s[0]=="#"]
g=[0,1][s[0]=="."]
b=[f]
w=[0]
#print(b,w)
for i in s:
#    print(w)
    if f==1 and i=="#":
        b[-1]+=1
    elif f==1 and i==".":
        f=0
        if w[-1]!=0: w.append(1)
        else: w[-1]=1
    elif b[-1]!=0 and f==0 and i==".":
        w[-1]+=1
    elif f==0 and i=="#":
        f=1
        if b[-1]!=0: b.append(1)
        else: b[-1]=1
ans=min(sum(b)-b[-1],sum(w))
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

B = list(itertools.accumulate(S))

MIN = 10000000
cnt = []
for i in range(N):
    cnt.append(B[i] + N - B[N-1] + B[i] - i - 1)
    # MIN = min(MIN, cnt)
MIN = min(cnt)

S = list(set(S))
if len(S) == 1:
    MIN = 0

print(MIN)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
a = 0
b = 0
for i in range(n):
  if s[i] == ".":
    a += 1
  else:
    break
for i in range(n):
  if s[-1] =="#":
    b += 1
  else:
    break
sb = s.count("#")
sw = s.count(".")
if sb-b>sw-a:
  print(sw-a)
else:
  print(sb-b)

Submission status: Wrong Answer

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

k=0
j=0
for i in range(n-1):
	if s[n-1-i] == '.' and  s[n-2-i] =='#':
		k = n-1-i
		break
for i in range(n):
	if s[:i]!='.'*(i+1):
		j=i
		break

print( min( len( s[:k].replace('.','') ), len( s[j:].replace('#',''))  ))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S.count('.') == N or S.count('#') == N:
    print(S[0] * N)
elif S.count('.') == S.count('#'):
    print(0)
else:
    print(abs(S.count('.') - S.count('#')))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
# . が white
# # が black
right="#"

f_sharp = 0
for i in range(0, N):
  if S[i] == "#":
    f_sharp = i
    break

ans = 0
sharp = S[f_sharp:].count("#")
dot = S[f_sharp:].count(".")
print(min(sharp, dot))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
t=s.count("#")
r=s.count(".")
if t==-1 or r==-1:
    print(0)
else:
    l=[t,r]
    ans=0
    for i in range(n):
        if s[i]=="#":
            ans+=1
            t-=1
            l.append(ans+t)
            l.append(ans+r)
        else:
            ans+=1
            r-=1
            l.append(ans+t)
            l.append(ans+r)
print(min(l))

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)
else:
    for j in range(secondposition-1):
        if(s[j] == '#'):
            count2 += 1

    count1 = n - position

    print(count1 + count2)

Submission status: Wrong Answer

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

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

print(min(a, N-a))

Submission status: Wrong Answer

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

si=[]
k=[]
count = 0
flag = 0
for i in range(0,n):
    if flag == 0:
        if s[i] == '.':
            count += 1
        else:
            si.append(count)
            count = 1
            flag = 1
    else:
        if s[i] == '#':
            count += 1
        else:
            k.append(count)
            count = 1
            flag = 0

if len(si)>0:
    sa=si[0]
else:
    sa=0
if len(k)>0:
    ka=k[-1]
else: ka = 0

smax = sum(si) - sa

kmax = sum(k) - ka

ans = max(smax,kmax)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
while s.count("#.") != 0:
    ans += s.count("#.")
    s = s.replace("#.", "##")

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 10**8
li = [0]

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

    else:
        if(i==S[ind-1]):
            if(i=='#'):
                b[-1]+=1
            else:
                w[-1]+=1
        else:
            if(i=='#'):
                b+=[b[-1]+1]
            else:
                w+=[w[-1]+1]
b = [0]+b
w = [0]+w
for ind,i in enumerate(w):
    ans = min(ans,w[-1]-w[ind]+b[ind])



print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[-1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()

min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

x = len(l)//2
for i in range(x):
    m = (black[i] - black[0]) + (white[x] - white[i])
    min_num = min(m, min_num)

print(min_num)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N = makeInt(input_string[0])
    S = input_string[1].rstrip()
    if len(S) == 1:
        return 0
    if S == "#.":
        return 1
    S = list("."+S)
    w = "."
    b = "#"
    c = 0
    for i in range(N):
        if S[i] == b:
            if S[i-1] == w and S[i+1] == w:
                S[i] = w
                c += 1
                continue
        if i > 0 and S[i] == w:
            #print(S)
            #print(S[i])
            if S[i-1] == b:
                S[i] = b
                c += 1
    i = N
    if i == N:
        #print("a")
        #print(S)
        #print(S[i])
        if S[i-1] == b and S[i] == w:
            S[i] = b
            c += 1
    return c


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
temp = S.count('.')
cnt = min(temp, N)

for i in range(N):
    if S[i] == '#':
        temp += 2
    else:
        temp -= 1
    cnt = min(temp, cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
cd = 0 ; dh = 0
for i in range(0 , len(s)):
  if(s[i] == '.'):
    cd += 1
  else:
    dh += 1
print(min(dh , cd))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s = list(s)
l = 0
r = len(s)
for i in range(len(s)):
        if s[i] == "#":
                l = i
                break
for i in range(len(s))[::-1]:
        if s[i] == ".":
                r = i
                break
ss = s[l:r+1]
ans = 10**6
for i in range(len(ss)):
        ans = min(ans,ss[:i+1].count("#")+ss[i+1:].count("."))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(1,N,1):
    if S[i-1] == "#" and S[i] == ".":
        cnt +=1
bcount = S.count("#")
wcount = S.count(".")
if bcount > wcount:
    print(cnt)
else:
    print(min(bcount,wcount,cnt))

Submission status: Wrong Answer

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

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

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

print(cnt)

Submission status: Wrong Answer

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

w = S.count(".")
b = S.count("#")

if w > b:
    change = "."

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

Submission status: Wrong Answer

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

num = 0
result = 0

if S[N-1] ==".":
    dot = S.count(".")
    if dot > N-dot:
        print(N-dot)
        exit()

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

white = S[0:num].count('.')
black = S[0:num].count('#')
if white < black:
    result = white
else:
    result = black
print(result)

Submission status: Wrong Answer

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

i = s.find("#")
if i < 0:
  i = 0
a = s[i:].count(".")
b = s.count("#")

if a < b:
  print(a)
else:
  print(b)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


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



pre = s[0]
for i in range(1, n):
    if pre=='#' and s[i]=='.':
        temp = i
        break
    pre = s[i]


# print(temp)
try:
    s = s[temp:]
    ans = sum(1 for x in s if x=='.')
    ans2 = sum(1 for x in s if x=='#') + 1
    if s[-1]=='#':
        ans -=1
        ans2 -=1

    print(min(ans, ans2))
except:
    print(0)

Submission status: Wrong Answer

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

sp_pos = S.find('#')
dot_num = S[sp_pos+1:].count('.')

dot_pos = S.rfind('.')
sp_num = S[:dot_pos].count('#')

print(min(dot_num, sp_num))

Submission status: Wrong Answer

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

flag = 0
ans1 = 0
for i in range(n):
  if S[i] == '.':
    if flag == 1:
      ans1 += 1
  else:
    flag = 1
    
flag = 0
ans2 = 0
for i in range(n-1, -1, -1):
  if S[i] == '#':
    if flag == 1:
      ans2 += 1
  else:
    flag = 1
    
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = min(S.count("#"), S.count("."))
for i in range(N):
	tmp = S[: i].count("#") + S[i:].count(".")
	if ans < tmp:
		ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
S=list(map(str,input()))

index_num = [n for n,v in enumerate(S) if v =='.']
count = 0
for i in index_num:
    if i!=0 and S[i-1]=='#':
        count += 1
print(count)

Submission status: Wrong Answer

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

count = 0
while '#.' in S:
    temp = S.replace('#.', '*')
    count += temp.count('*')
    temp = temp.replace('*.', '...')
    temp = temp.replace('*#', '###')
    S = temp.replace('*', '##')
print(count)

Submission status: Wrong Answer

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

print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
print(min(s.count("."),s.count("#")))

Submission status: Wrong Answer

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

pattern = re.compile(r"#.")
_, count = re.subn(pattern, "##", S)
print(count)

Submission status: Wrong Answer

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

S = S[::-1]
while len(S) :
    if S[0] == "#" :
        S = S[1:]
    else :
        break

if len(S) :
    S = S[::-1]

    a = S.count("#")
    b = len(S) - a
    print(min(a,b))
else :
    ans = 0

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
#import random
#S = "".join([["#", "."][random.randint(0, 1)] for _ in range(10)])
#print(S)
S = S[:S.rfind(".") + 1]
#print(S)
l = S.find("#") + 1
#print(S[l:])
print(min(S.count("#"), S[l:].count(".")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 0
for i in range(2,n):
    if s[i]=='.':
        if s[i-1] == '.':
            if s[i-2] == '#':
                s[i-2] = '.'
                ans += 1
        else:
            if s[i-2] == '.':
                s[i-1] = '.'
                ans += 1
            else:
                s[i] = '#'
                ans +=1
    else:
        if s[i-1] =='.':
            if s[i-2] =='#':
                s[i-1] = '#'
                ans += 1

print(ans)

Submission status: Wrong Answer

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

def check(n,s):
    for i in range(1,n):
        if s[i-1] == "#" and s[i] == ".":
            return False
    return True
N = int(input())
S = input()

b = S.count("#")
w = S.count(".")
if b == 0 or w == 0 or check(N,S):
    print("0")
elif b <= w:
    print(b)
else:
    print(w)

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 == "#" and not i == N-1:
			count+=1

count2=N-count
print(min([count,count2]))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = [str(i) for i in input()]

    black_num = 0
    white_num = 0
    pre_white_num = 0

    last_color = "black"

    for s in S:
        if s == "#":
            black_num += 1
            if black_num == 1:
                pre_white_num = white_num
        elif s == ".":
            white_num += 1

    white_num -= pre_white_num

    if S[-1] == "#":
        last_color = "black"
    else:
        last_color = "white"

    if last_color == "black":
        black_num -= 1

    print(min([black_num, white_num]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())

a=0
f = False
for i in range(len(S)-1):
    if (S[i]=='#') & (S[i+1]=='.'):
        if not f:
            S[i]='.'
            f = False
        else:
            S[i+1]='#'
            f = True
        a += 1
print(a)

Submission status: Wrong Answer

Solution code:
_ = input()

letter = input()

cnt_forward = 0
for i in range(len(letter) - 1):
    if letter[i] == '#' and letter[i+1] == '.':
        for c in letter[i+1:]:
            if c == '.':
                cnt_forward += 1
                
        break

cnt_backward = 0
for i in range(1, len(letter)):
    if letter[-i] == '.' and letter[-i-1] == '#':
        for c in letter[-i::-1]:
            if c == '#':
                cnt_backward += 1
        
        break
                
print(min(cnt_forward, cnt_backward))

Submission status: Wrong Answer

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

# input

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



for idx, s in enumerate(S):
    if s == "#":
        S = S[idx:]
        break


w_n = S.count(".")
b_n = S.count("#")

if N==w_n or N==b_n:
    print(0)
    exit()

if w_n <=b_n:
    ans = w_n
else:
    ans = b_n



print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    S = list(input())
    
    count_sharp = S.count('#')
    count_dot = S.count('.')
    # print(count_sharp, count_dot, count_sharp < count_dot)
    count = 0


    
    for i in range(1, len(S)):
        # print(S, end='')
        one = S[i-1]
        two = S[i]
        
        if count_sharp < count_dot:
            if (one == '#') and (two == '.'):
                count += 1
                S[i-1] = '.'
            elif (one == '#') and (two == '#'):
                S[i-1] = '.'
                count += 1
        else:
            S[i-1] = '#'
        # print(S)

    print(count)
    # #..#.#....##...# -> (.)..(.).(.)....(.)(.)...#

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cou = 0
for i in range(1, len(s)):
    if s[i-1] == '#':
        if not s[i-1] == s[i]:
            s[i] = '#'
            cou += 1

print(cou)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
N = int(input())
S = input()
a = 0

for i in range(N):
    if i == N - 1 and S[N - 1] == '.':
        break
    elif i == N:
        break
    if S[i] == '#' and S[i + 1] == '.':
        a += 1

print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = list(S)
K = S.copy()
T = S.copy()

res1 = 0
for i in range(N-1):
    if S[i] == '#' and S[i+1] == '.':
        res1 += 1
        S[i+1] = '#'
        
res2 = 0
for i in range(N-1):
    if T[i] == '#' and T[i+1] == '.':
        res2 += 1
        T[i] = '.'
        
res3 = 0
b = 0
w = 0
for i in range(N):
    if K[i] == '#':
        b += 1
    else:
        w += 1

res3 = N - max(b, w)

print(min(res1, res2, res3))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
memo = 0
count = 0
if "#" in S:
    count = S.count(".")

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ansW = 0
ansB = 0

def indB(str) :
	for i in range(n) :
		if str[i] == "#" : 
			return i
	return -1

indexB = indB(s)
if indexB != -1 :
	for i in range(indexB, n) :
		if s[i] == "." : 
			ansW += 1
            
def indW(str) :
	for i in range(n-1,-1,-1) :
		if str[i] == "." : 
			return i
	return -1

indexW = indW(s)
if indexW != -1 :
	for i in range(indexW,-1,-1) :
		if s[i] == "#" : 
			ansB += 1

print (min(ansW,ansB))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = str(input())
ans=0
chk=0
for i in range(N-1):
    if chk == 1:
        if S[i]==".":
            chk = 1
            ans = ans +1
        else:
            chk =1
    elif chk == 0:
        if S[i]==".":
            chk=0
        else:
            chk=1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if "." not in s or "#" not in s:
    print(0)
    exit()

f,f2 = 0,0
res,res2 = 0,0
for i,j in zip(s,reversed(s)):
    if f == 1 and i==".":
        res += 1
    if i=="#":
        f = 1
    if f2 == 1 and j=="#":
        res2 += 1
    if j==".":
        f2 = 1

else:
    print(min(res,abs(n-res)-1,res2-1,abs(n-res2)))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
s2 = list(s)
cnt = 0
cnt2 = 0
print(min(s.count("#"), s.count(".")))

Submission status: Wrong Answer

Solution code:
black = '#'
white = '.'

def main():
    n = int(input())
    s = input()

    ans = 0

    for i in range(len(s)):
        if needToChange(s, i):
            s = s[:i] + black + s[i + 1:]
            ans += 1

    print(ans)

def needToChange(s, i):
    if s[i] == white:
        return False
    if i >= len(s) - 1:
        return False
    if s[i + 1] == white:
        return True
    return False

main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
stones_count = int(input())
input_str = input()

target = input_str[0]

def set_next_target(target_char):
  if target_char == '#':
    return '.'
  else:
    return '#'

stones = ''
stones_list = []

for i in range(stones_count):
  if input_str[i] == target:
    stones = stones + target
  else:
    stones_list.append(stones)
    target = set_next_target(target)
    stones = target

stones_list.append(stones)
#print(stones_list)

count_0 = 0
count_1 = 0

if len(stones_list) == 2 and '#' in stones_list[-1]:
  print(0)
  exit()

for i in range(len(stones_list)):
  if i % 2 == 0:
   count_0 += len(stones_list[i])
  else:
   count_1 += len(stones_list[i])

if count_0 > count_1:
  print(count_1)
else:
  print(count_0)

Submission status: Wrong Answer

Solution code:
import sys
a = []
for l in sys.stdin:
    a.append(l)

haichi = a[1].split()[0]
prev_haichi = '.'
count = 0
for each_haichi in haichi:
    if prev_haichi == '#' and each_haichi == '.':
        count += 1
        prev_haichi = '#'
    else:
        prev_haichi = each_haichi
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S == '.' * N:
  print(0)
else:
  first = 0
  for i in range(1,N+1):
    if S[i-1] == '#':
      first = i
      break
  out1 = 0
  for i in range(first+1,N+1):
    if S[i-1] =='.':
      out1 += 1
  second = 0
  for i in range(1,N+1):
    if S[N-i] == '.':
      second = i
      break
  out2 = 0
  for i in range(first+1,N+1):
    if S[N-i] =='#':
      out2 += 1
  print(min(out1,out2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

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

	ans = 0
	flg = False
	for i in S:
		if i == "#":
			flg = True
			continue
		if flg == True and i == ".":
			ans += 1
			flg = False

	print(ans)

	

	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
end = len(s) -1

s1 = s[:]
i = 0
ans1 = 0
while(i < end):
    c = s1[i] + s1[i+1]
    if c == '#.':
        s1 = s1[:i] + '.' + s1[i+1:]
        ans1 = ans1+ 1
    i += 1

s2 = s[:]
i = 0
ans2 = 0
while(i < end):
    c = s2[i] + s2[i+1]
    if c == '#.':
        s1 = s1[:i+1] + '#' + s1[i+2:]
        ans2 = ans2 + 1
    i += 1


if ans1 <= ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    s = s.split('#', 1)[-1]
    print(min(s.count('.'), s.count('#')+1))

Submission status: Wrong Answer

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

start = len(s)
frag = False
i = 0
kuro = 0
while(i<len(s)):
    if(s[i]=="#" and not(frag)):
        frag = True
        start = i
        i += 1
        kuro += 1
    elif(s[i]=="." and frag):
        start = i - 1
        i = len(s)
    elif(frag):
        kuro += 1
        i += 1
    else:
        i += 1

if(start == len(s)):
    print("0")
else:
    shiro = 0
    for i in range(len(s)-start-1):
        if(s[i+start+1]=="."):
            shiro += 1
        else:
            kuro += 1
    if(kuro<=shiro):
        if(s[len(s)-1]=="#"):
            print(kuro-1)
        else:
            print(kuro)
    else:
        print(shiro)

Submission status: Wrong Answer

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

c = 0
for i in range(N):
      if S[N-1-i] == "#":
            c += 1
      else:
            break
if c > 0:
      S = S[:-c]

cc = 0

for j in range(N-c):
      if S[j] == ".":
            cc += 1
if N-cc>0:
      print(min(cc, N-cc))
else:
      print("0")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
t = s[::-1]
ans = 0
cnt = 0
cnt2 = 0
res = 0
for i in s:
    if i==".":
        ans += 1
    else:
        res += 1
for i in s:
    if i==".":
        cnt += 1
    else:
        break
for i in t:
    if i=="#":
        cnt2 += 1
    else:
        break

print(min(ans-cnt,res-cnt2))

Submission status: Wrong Answer

Solution code:
import re

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

s = re.sub('^\.*(#.+)', r'\1', s)
print(0 if '#' not in s else s.count('.'))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 0
b = 0
curw = 0
curb = 0
if n == 1:
    print(0)
    exit()
for i in range(n-1,-1,-1):
    if s[i] != "." and b == 0:
        continue
    if s[i] =="." and (b == 0 or b == 1):
        curw += 1
        b = 1
    if s[i] !="." and b == 1:
        curb += 1
        b = 2
    if s[i] == "." and b ==2:
        ans += min(curb,curw)
        b = 1
        curw += 1
if s[0] != "." and s[1] == ".":
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
N = int(input())
S = input()

min = N
if S.count('#') == N or S.count('.') == N:
    print(0)
else:
    l = 0
    r = S.count('.')
    for n in range(1,N+1):
        if S[n-1] == '#':
            l += 1
        else:
            r -= 1
        if l+r < min:
            min = l+r
    print(min)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=input()
sflag=0
a=0
b=0
c=0



for i in S:
    if i==".":
        a+=1
    if i=="#":
        b+=1
    if i=="." and sflag==0:
        sflag=1
    if sflag==1:
        if i=="#":
            c+=1

"""
for i in S:
    if i=="#" and sflag==0:
        sflag=1
    if sflag==1:
        if i==".":
            a+=1
        else:
            b+=1

a2=0
sflag=0
for i in S[::-1]:
    if i=="." and sflag==0:
        sflag=1
    if sflag==1:
        if i=="#":
            a2+=1
        #else:
        #    b2+=1
"""
print(min(a,b,c))

Submission status: Wrong Answer

Solution code:
n=int(input())
st=input()
flag=False
count=0
for i in range(n):
	if st[i]=='#' and not flag:
		flag=True
	if flag and st[i]=='.':
		count+=1
count1=0
flag=False
for i in range(n):
	if st[n-i-1]=='.' and not flag:
		flag=True
	if flag and st[n-i-1]=='#':
		count1+=1
count2=st.count('#')
count3=n-count2
print(min([count,count1,count2,count3]))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
B_C = 0
W_C = 0
for i in range(N):
    if S[i] == ".":
        W_C += 1
    elif S[i] == "#":
        B_C += 1
#print(W_C,B_C)
#print(min(W_C,B_C))

if B_C >= W_C:
    pair = 0
    for i in range(N-1):
        if S[i] == "#" and S[i+1] == ".":
            pair += 1
    print(pair)
else:
    print(B_C)

Submission status: Wrong Answer

Solution code:
def cutw(s,n):
    t = 0
    for i in range(n):
        if s[i] == '#':
            break
        else:
            t += 1
    s = s[t:]
    n = len(s)
    return s,n

def cutb(s,n):
    t = n
    for i in range(n-1, -1,-1):
        if s[i] == '.':
            break
        else:
            t -= 1
    s = s[:t]
    n = len(s)
    return s,n

def main():
    n = int(input())
    s = input()
    res = 0
    s1 = s
    n1 = n
    res1 = 0
    s,n = cutw(s,n)
    s,n = cutb(s,n)
    if n>0:
        s = '.'+s[1:]
        res += 1
    res += min(s.count('.'),s.count('#'))
    s1,n1 = cutw(s1,n1)
    s1,n1 = cutb(s1,n1)
    if n1>0:
        s1 = s1[:n1-1] + '#'
        res1 += 1
    res1 += min(s1.count('.'),s1.count('#'))
    print(min(res,res1))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if s == '.' * n or s == '#' * n:
    print(0)
    exit()

idx = -1
for i, c in enumerate(s):
    if c == '#':
        idx = i
        break

print(min(s[idx:].count('.'), ( s[idx:].count('#') - 1 if s[n - 1] == '#' else s[idx:].count('#'))))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().split("#")
print(S[1:].count("."))

Submission status: Wrong Answer

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

N=int(input())
S=input()
lb=None
for i in range(N):
    if S[N-i-1] == "#":
        lb=N-i-1
if lb==None:
    print(0)
    exit(0)
rw=None
for i in range(N):
    if S[i]==".":
        rw=i
if rw==None:
    print(0)
    exit(0)
nw=0
nb=0
for i in range(lb, rw+1):
    if S[i] == "#":
        nb = nb+1
    if S[i] == ".":
        nw = nw+1

if lb != None:
    print(min(nb, nw))
else:
    print(0)

Submission status: Wrong Answer

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

B = 0
W = 0

for i in range(0,N):
    if S[i] == '#':
        B = B+1
    else:
        W = W+1
if W >= B:
    print(B)
else:
    print(W)

Submission status: Wrong Answer

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

X = [0 if x == '#' else 1 for x in S] # 0:black 1:white
Y = list(reversed(X))

if 0 not in X or 1 not in X:
    ans = 0 
else:
    idx = X.index(0) # first black
    X = sum(X[idx:])
    Y = N - idx - X - Y.index(1)
    ans = min(X, Y)

print(ans)