Problem:


Score : 300 points

Problem Statement

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
#.#

Sample Output 1

1

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

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
import sys,copy
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

n = int(input())
S = list(input())
T = copy.copy(S)
cnt = 0
for i in range(1,n):
    if S[i-1] == '#' and S[i] == '.':
        cnt += 1
        S[i] = '#'
tmp = 0
T = T[::-1]
for i in range(n-1):
    if T[i] == '.' and T[i+1] == '#':
        tmp += 1
        T[i+1] = '.'
#print(cnt,tmp)
print(min(cnt,tmp))

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
for i in range(n):
    #print(i)
    if i<=n-2:
        if s[i] == "#" and s[i+1]==".":
            s[i+1]="#"
            ans+=1
    if 1<=i:
        if s2[i]=="." and s2[i-1]== "#":
            s2[i-1]="."
            ans2+=1

#print(s)
#print(s2)
#print(ans,ans2)
print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
N = int(input())
S = list(input())
S1, S2 = S[:], S[:]
c1, c2 = 0, 0
for i in range(N-1):
    if S1[i] == "#" and S1[i+1] == ".":
        c1 += 1
        S1[i+1] == "#"
    if S2[i] == "#" and S2[i+1] == ".":
        c2 += 1
        S2[i] = "."
print(min(c1, c2))

Submission status: Wrong Answer

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

exe1 = ""
exe2 = ""
exe3 = ""

for i in range(n):
  exe1 = exe1 + "#"
  exe2 = exe2 + "."
  if i < n-1:
    exe3 = exe3 + "."
  else:
    exe3 = exe3 + "#"
    
cnt1 = 0
cnt2 = 0
cnt3 = 0

for i in range(n):
  if s[i] != exe1[i]:
    cnt1 += 1
  if s[i] != exe2[i]:
    cnt2 += 1
  if s[i] != exe3[i]:
    cnt3 += 1
    
mincnt = cnt1
if mincnt > cnt2:
  mincnt = cnt2
if mincnt >cnt3:
  mincnt = cnt3
  
print(mincnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
print(min(S.count("#"), S.count(".")))

Submission status: Wrong Answer

Solution code:
import re
import sys
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    S = ii(str)
    S = S[::-1]
    if S[0] == ".":
        return min(S.count("#"), S.count("."))
    S = S[S.find(".") :]
    s = S.count("#")
    t = S.count(".")
    return min(s, t)

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

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

black = -1
white = N

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

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

cnt_white = S[black+1:].count(".")
cnt_black = S[:white].count("#")
ans = min(cnt_white,cnt_black)
print(ans)

Submission status: Wrong Answer

Solution code:
N  = int(input())
S = input()
black = S.count("#")
white = N - black
ans = min(black , white)
if black == 0 or white == 0:
    print(0)
else:
    temp = 0
    for i in range(N-1):
        if S[i] == '#':
            black -= 1
            white += 1
            temp += 1
            ans = min(ans, temp + black , temp + white) 
    print(ans)

Submission status: Wrong Answer

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

ans = 0

for i in range(N-1):
  #print(i,end="")
  #print(S[i])
  if S[i]=="#" and S[i+1]==".":
    ans=ans+1
    
print(ans)

Submission status: Wrong Answer

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

num = 0
for i in range(n):
    print(s[i])
    try:
        if s[i] == '#' and s[i+1] == ('.'):
            num += 1
            s[i+1] = '#'
        else:
            pass
    except:
        break
print(num)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 21:15:50 2019

@author: doppe
"""

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

countBlack = 0
countWhite = 0

for c in S:
    if (c == '.'):
        countWhite += 1
    else:
        countBlack += 1

countRightWhite = 0
countLeftBlack = 0
for c in S:
    if (c == '.'):
        countRightWhite += 1
    else:
        break
for c in range(len(c) - 1, -1, -1):
    if (S[c] == '#'):
        countLeftBlack += 1
    else:
        break

black = countWhite - countRightWhite
white = countBlack - countLeftBlack

if (white < black):
    print(white)
else:
    print(black)

Submission status: Wrong Answer

Solution code:
N=int(input())

c="$"
lg=0
ou=[]

for s in input():
	if s == c:
		lg += 1
	else:
		ou.append((c, lg))
		lg = 1
		c = s

ou.pop(0)
ou.append((c, lg))

ans=0
b=(".",0)
for s,l in ou:
	bs,bl = b
	if bs == "#" and s == ".":
		ans += min(bl, l)
	b = (s,l)

print(ans)

Submission status: Wrong Answer

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


for i in range(n):
  if s[i] == '.':
    s[i] = ''
  if s[i] == '#':
    break

s = s[::-1]

for i in range(n):
  if s[i] == '#':
    s[i] = ''
  if s[i] == '.':
    break

ans1 = s.count('.')
ans2 = s.count('#')
print(min([ans1, ans2]))

Submission status: Wrong Answer

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

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

print(q)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

target = S[0]
cnt = 0
for i in range(1, N):
    if target == '#' and S[i] == '.':
        cnt += 1
        target = '#'
        continue

    if S[i] == '#':
        target = '#'
    else:
        target = '.'

cnt_2 = 0
target = S[-1]
for i in range(N-1, -1, -1):
    if target == '.' and S[i] == '#':
        cnt_2 += 1
        target = '.'
        continue

    if S[i] == '#':
        target = '#'
    else:
        target = '.'

print(min(cnt, cnt_2))

Submission status: Wrong Answer

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

s = input()
S = list(s)

ans = 0
tmpW = 0
tmpB = 0
pre = -1

for s in S[::-1]:
    if s == '.' and pre == -1:
        tmpW += 1
        pre = 1

    elif s == '.' and pre == 1:
        tmpW += 1

    elif s == '.' and pre == 2:
        if tmpW < tmpB:
            ans += tmpW
        else:
            ans += tmpB
        pre == 1
        tmpW = 1
        tmpB = 0

    elif s == '#' and pre == 1:
        tmpB += 1
        pre = 2

    elif s == '#' and pre == 2:
        tmpB += 1

if tmpB == 0:
    pass
elif tmpW < tmpB:
    ans += tmpW
else:
    ans += tmpB

print(ans)

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)
nw=0
nb=0
for i in range(lb, N):
    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=input()
cnt1 = 0
cnt2 = 0
for idx,s in enumerate(S):
    if s != "." and idx != N-1:
        cnt1 += 1
    if s!="#":
        cnt2+=1
print(min([cnt1,cnt2]))

Submission status: Wrong Answer

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

sum = 0
sb = 0
sw = 0

for i in range(len(s)):
    if s[i] == '.':
        sw += 1
    else:
        sum += min(sb,sw)
        if (sb > sw):
            sb += sw + 1
            sw = 0
        else:
            sw = 0
            sb = 1

sum += min(sb,sw)

print(sum)

Submission status: Wrong Answer

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

if ('.' not in S) or ('#' not in S):
    print(0)
    exit()

flag = False
cnt = 0
for char in S:
    if char == '#':
        flag = True

    if char == '.' and flag:
        cnt += 1
        flag = False

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
S = input()
ans = S.count('.')
num = 0
for x in S:
    if x == '#':
        break
    else:
        num += 1
c = S.count('#')
d = 0
for x in S[::-1]:
    if x == '.':
        break
    else:
        d += 1
print(min(ans-num, c-d))

Submission status: Wrong Answer

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

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

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

white = N-first_black-cnt+1
if white > cnt:
    print(cnt)
else:
    print(white)

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

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

white = 0
black = 0

for i in range(N):
  if S[i] == "#":
    black +=1
  else:
    white +=1

print(min(white,black))

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:
n=int(input())
s=input()


black=0
white=0
for st in s:
  if st=="#":
    black=black+1
  else:
    white=white+1
change=0
s = list(s)

if black>white:
  for i in range(n-1):
    if s[i]=="#" and s[i+1]==".":
      change=change+1
      s[i+1]="#"

else:
  for i in range(n-1):
    if s[i]=="#" and s[i+1]==".":
      change=change+1
      s[i]="."

if change > n - change:
  change=n-change
print(change)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
import copy
ss= copy.copy(s)
c=0
d=0
for i in range(0,n-1,1):
    if s[i] == "#" and s[i+1] == ".":
        s[i+1] = "#"
        c+=1
    if ss[i] == "#" and ss[i+1] == ".":
        ss[i] = "."
        d+=1

if c>d:
    print(d)
else:
    print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ret = 0
if len(S) != 1:
  for i in range(1,len(S)):
    if(S[i-1]+S[i] == '#.'):
      ret += 1

print(ret)

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
        if S[i] == w:
            if S[i-1] == b and S[i+1] == w:
                S[i-1] = w
                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 = list(input())
S_copy = S[:]
count_1 = 0
count_2 = 0
for i in range(N-1):
  if S_copy[i] == "#" and S_copy[i+1] == ".":
    count_1 += 1
    S_copy[i] = "."
for i in range(N-1):
  if S[N - i - 1] == "." and S[N - i - 2] == "#":
    count_2 += 1
    S[N-i-2] = "."
      
    
print(min(count_1, count_2))

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):
        if S[n-1] == '#':
            l += 1
        else:
            r -= 1
        if l+r < min:
            min = l+r
        print(min)
    print(min)

Submission status: Wrong Answer

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


all_w = len(S) - S.count(".")
all_b = len(S) - all_w

other = 2*10000000
if S[-1] == '#':
    other = all_w - 1

print(min(all_w,all_b,other))

Submission status: Wrong Answer

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

s = list(S)

for i in range(N-1, -1, -1):
    if s[i] == "#":
        s[i] = ""
    else:
        break
    
for i in range(N):
    if s[i] == ".":
        s[i] = ""
    else:
        break

s1 = s.count(".")
s2 = s.count("#")

print(min(s1, s2))

Submission status: Wrong Answer

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

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

c = [0]
cc = [0]
for i in range(n):
  if s[i] == ".":
    c.append(c[-1]+1)
    cc.append(cc[-1])
  else:
    c.append(c[-1])
    cc.append(cc[-1]+1)
c = c[1:]
cc = cc[1:]

a = cc.count(0)
print(min(c[-1]-a, cc[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
location = 9999999
for i in range(n):
    if s[i] == '#':
        location = i
        break

if location == 9999999:
    print(0)
else:
    print(s[location:n].count('.'))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    n = 0b0
    ans = 0
    for s in S:
        #print("{0:0100b}".format(n))
        n<<=1
        if s == "#":
            n += 0b1
        if n & 0b11 == 0b10:
            ans += 1
            n = n&0b00|0b01
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

res = float("inf")

counts = []
counts.append((0, 0))
a, b = 0, 0
for s in S:
    if s == "#":
        a += 1
    elif s == ".":
        b += 1
    counts.append((a, b))

for i in range(N):
    res = min(res, counts[i + 1][0] + counts[-1][1] - counts[i + 1][1])

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
sl = list(s)
k = 0
for i in range(n-1):
   if sl[i]=="#" and sl[i+1]==".":
      sl[i+1]='#'
      c = c + 1
      if c == 1:
        k = i
cc = sl.count('#')
if cc < sl[k:].count("."):
   c == cc
print(c)

Submission status: Wrong Answer

Solution code:
a = int(input())
s = list(input())
ans2 = s.count('#')
ans3 = s.count('.')
ans = 0
for i in range(a-1):
    if(s[i] == "#" and s[i+1] == "."):
        ans += 1
        s[i+1] = "#"
        
print(min(ans2, ans, ans3))

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),res2,abs(n-res2)))

Submission status: Wrong Answer

Solution code:
def third_select(S):
    right = N - 1
    change = 0
    sharp_appeared = False
    for i, s in enumerate(S[::-1]):
        if s == '#':
            sharp_appeared = True
        elif sharp_appeared:
            right = N - i
            break
        else:
            change += 1

    for s in S[:right]:

        if s == '#':
            change += 1
    return change

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

ALL_period = S.count('#')
ALL_sharp = N - ALL_period



print(min(ALL_period, ALL_sharp, third_select(S)))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
white = S.count(".")
try:
    bindex = S.index("#")
except ValueError:
    bindex = 0
black = S[bindex:].count("#")
bwhite = S[bindex:].count(".")
print(min(black,bwhite))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
A = []
for i in range(N):
    if S[i] == "#":
        A.append(i)
try:
    ans = N-min(A)-len(A)
except:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = S.rstrip('#')
N = len(S)
cnt = S.count(".")
if cnt == N:
  print(0)
elif cnt > N/2:
  print(N-cnt)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sl = []
count = 0
state = 0
b = 0
w = 0
for i in range(n):
    if s[i] == "#":
        if state == 0:
            state = 1
            b += 1
        elif state == 1:
            b += 1
        elif state == 2:
            count += min([b,w])
            b = 1
            w = 0
            state = 1
    else:
        if state == 1:
            state = 2
            w += 1
        elif state == 2:
            w += 1

if state == 2:
    count += min([b,w])

print(count)

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
print(min([count,count1]))

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

a = list(input())
su = 0
co = 1
if a[-1] == "#":
	co = 2
for i in range(n-1):
	if a[-(i+2)] == "#" and co == 1:
		su += 1
	elif a[-(i+2)] == "." and co == 2:
		co = 1
print(su)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
x=n
for i in range(n):
    if s[i]=="#":
      x=i
      break
b=s[x:].count("#") 
w=len(s[x:])-b
print(b if b<w else w)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(raw_input())
S = str(raw_input())
all_sharp = S.count('.')

for i in range(N):
	if S[N-i-1] == '.':
		num = i
		all_dot = S[:N-num].count('#')
		print min(all_sharp, all_dot)
		sys.exit()
	else:
		print 0

Submission status: Wrong Answer

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

if b > w:
    print(w)
else:
    print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
k,d = 0,0
s = list(input())
 
for i in s:
  if i == '#':
    k+=1
  else:
    d+=1
print(min(k,d))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
S = [str(c) for c in s]

cnt1 = 0; #　.の数
cnt2 = 0;#　#の数

for i in range(N):
    if str(S[i]) == "." and str(S[i-1])=="#":
        cnt1 += 0
    elif str(S[i]) == "#" and str(S[i-1])==".":
        cnt1 += 1
    elif str(S[i]) == "#" and str(S[i-1])=="#":
        cnt1 += 0
    elif str(S[i]) == "." and str(S[i-1])==".":
        cnt1 += 0

print(cnt1)

Submission status: Wrong Answer

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

n = S.find("#")
if n < 0:
  print(0)
else:
  print(min(S[n:].count("."), S.count("#")))

Submission status: Wrong Answer

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

print(min(ans-cnt,res))

Submission status: Wrong Answer

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

print(cnt)

Submission status: Wrong Answer

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

A = S.count("#")
B = S.count(".")

if(A == 0 or B == 0):
    print("0")
else:
    print(min(A,B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S = list(S)
ans = 0
# for i in range(N):
#     if i+1 < N:
#         if S[i] == '#' and S[i+1] == '.':
#             S[i+1] = '#'
#             ans += 1
flag = 0
flag = S.count('#')
if flag > 0:
    ans = S.count('.')

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
count = 0
ans = 10 ** 7
for i in s:
    if i == ".":
        count += 1
for i in s:
    if i == "#":
        count += 1
        ans = min(ans,count)
    else:
        count -= 1
        ans = min(ans,count)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
min_ans = 2*10**5
ideal1 = "."*N
ideal2 = "."*(N-1) + "#"
ideal3 = "#"*N
ideal4 = "." + "*"*N
ideals = [ideal1,ideal2,ideal3,ideal4]
for ideal in ideals:
    ans = 0
    for i in range(N):
        if S[i] != ideal[i]:
            ans += 1
    if ans < min_ans:
        min_ans = ans
print(min_ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S.find('#.') >= 0:
    if S.count('#') > S.count('.'):
        print(S[S.find('#'):].count('.'))
    else:
        print(S[:N-1].count('#'))
else:
    print(0)

Submission status: Wrong Answer

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

# input

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

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

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

ans = 0
flg = False
for i in range(len(S)):
    if i == 0:
        continue

    if i == 1:
        a = S[i - 1]
        b = S[i]
        if a == "#" and b == ".":
            ans += 1
            continue
    if flg:
        a = "#"
        flg = False
    else:
        a = S[i-1]
    b = S[i]

    if a=="#" and b==".":
        flg = True
        ans +=1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
s2 = list(s)
cnt = 0
cnt2 = 0
for i in range(n):
    if i == 0:
        pass
    else:
        if s[i-1] == "#" and s[i] == ".":
            s[i] = "#"
            cnt += 1
for i in range(n):
    if i == 0:
        pass
    else:
        if s2[i-1] == "#" and s2[i] == ".":
            s2[i-1] = "."
            cnt2 += 1
print(min(cnt, cnt2))

Submission status: Wrong Answer

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

sl = []
for i in range(n):
    sl += s[i]

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


print(c)

Submission status: Wrong Answer

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

k=0
j=0
for i in range(n):
	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()
cmp1,cmp2 = 0,0

if s.count('.') == n:
    print('0')
else:
    cmp1 = s[s.index('#'):].count('.')
    cmp2 = s[s[::-1].index('#'):-1].count('#')
    print(min(cmp1,cmp2))

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
w0,w1,b0,b1 = 0,0,0,0

for s in S:
    if(s=="."):
        #print("w")
        if(fastB and fastW):
            w1+=1
        else:
            fastW=True
            w0+=1
    elif(s=="#"):
        #print("b")
        if(fastB and fastW):
            b1+=1
        else:
            fastB=True
            fastW=True
            b0+=1

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

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

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
print(min(a,b))

Submission status: Wrong Answer

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

ans = 0
has_black = False
has_white = False
cnt_black = 0
cnt_white = 0
for c in s:
    if c == '#':
        if has_black and has_white:
            # has_black = False
            has_white = False
            ans += min(cnt_white, cnt_black)
            cnt_white = 0
            cnt_black = 1
        else:
            has_black = True
            cnt_black += 1
    elif c == '.' and has_black:
        has_white = True
        cnt_white += 1

if c == '.':
    ans += min(cnt_black, cnt_white)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = list(input())
memo = 0
counter = 0
if "#" in S:
    count = collections.Counter(S)
    counter = count["."]

print(counter)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math

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

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

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    S = list(_ for _ in input())
    S_num = []
    index = 0 #
    now = ''
    if(S[0]=='#'):
        S_num.append(1)
        now = '#'
    else:
        S_num.append(-1)
        now = '.'
        
    for i in range(1,N):
        if(S[i]=='#' and now =='#'):
            S_num[index] +=1
        elif(S[i]=='.' and now =='.'):
            S_num[index] +=-1
        elif(S[i]=='#' and now !='#'):
            S_num.append(1)
            now = '#'
            index +=1
        elif(S[i]=='.' and now !='.'):
            S_num.append(-1)
            now = '.'
            index +=1
    # print(S_num)
    ans = 0
    for i in range(len(S_num)-1):
        if(S_num[i]>0 and S_num[i+1]<0):
            ans += min(S_num[i],-S_num[i+1])
            
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

bef=""
now = s[0]
count=0
# なるべく連鎖しないように
for i in range(0,n-1):
    if now == "#" and s[i+1]==".":
        if i > 0 and bef==".":
            count+=1
            now = "."
            continue
        bef="#"
        count+=1
        continue
    bef=now
    now = s[i+1]
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
d = []
for c in s:
    if d==[]:
        d.append([c,1])
    else:
        if c == d[-1][0]:
            d[-1][1]+=1
        else:
            d.append([c,1])

endwhite = 0
endblack = 0
white = 0
black = 0
total = 0
for p in d:
    if p[0] == '.':
        endwhite = black
        endblack += p[1]
        white += p[1]
    if p[0] == '#':
        endblack = white
        endwhite += p[1]
        black += p[1]
print(min(endwhite,endblack))

Submission status: Wrong Answer

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

a=s.count("#")
b=s.count(".")
if a<b:
    if s[0]=="#":
        print(a-1)
    else:
        print(a)
else:
    if s[0]==".":
        print(b-1)
    else:
        print(b)

Submission status: Wrong Answer

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

ans = 100000
flag=False
for i,s in enumerate(S):
  if(i==0):
    last_s = s
    continue
  else:
    if last_s == "." and s == "#":
      flag=True
      cld = S[:i].count('.')
      clh = S[:i].count('#')
      crd = S[i+1:].count('.')
      crh = S[i+1:].count('#')
      ans=min(ans, min(cld,clh)+min(crd,crh))

    last_s = s

if(not flag): print(0)
else: print(ans)