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 math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnta = s.count("#")
cntb = s.count(".")
ans = min(cnta,cntb)
for i in range(N):
	if s[i] == "#":
		tmp = i
		ans = min(ans,N-(cnta-(i+1)))
		break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
iblack = s.find("#")
if iblack == -1:
    print(0)
    exit()

print(min(s[iblack:].count("."), s.count("#")))

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
l=""
for s in input():
	if l == "#" and s == ".":
		ans+=1
	l=s
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder C
"""
 
def main():
    N=input()
    S=list(map(str,input().split()))[0]
    tmp=False
    num=0
    for s in S:
        # print(s,tmp)
        if s=="#":
            tmp=True
        elif s=="." and tmp:
            num+=1

    num2=0
    for s in S:
        # print(s,tmp)
        if s=="#":
            num2+=1
    if S[-1]=="#":
        num2-=1
    print(min(num,num2))
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
fK = N
ansSK = 0
ansSS = 0
for i in range(N):
    if S[i] == '#':
        fK = i
        break
for j in range(fK,N-1):
    if S[j] == '.':
        ansSK += 1
    else:
        ansSS += 1
print(min(ansSK,ansSS))

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]



try:
    s = s[temp:]
    ans = sum(1 for x in s if x=='.')
    print(ans)
except:
    print(0)

Submission status: Wrong Answer

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

black_count = 0
white_count = 0
right_white_pos=0
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
    else:
        if(S[i]=="."):
            counter+=1

print(min(white_count, black_count, counter))

Submission status: Wrong Answer

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

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

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

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()
    s,n = cutw(s,n)
    s,n = cutb(s,n)
    print(min(s.count('.'), s.count('#')))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
if s.count('#') == 0:
    print('0')
    exit()
print(s[s.find('#'):].count('.'))

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
s=[False]*n
flag=False
count=0
for i in range(n):
	tmp=sys.stdin.read(1)
	if tmp=='#' and not flag:
		flag=True
	if flag and tmp=='.':
		count+=1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
inputS=input()
listS=list(inputS)
count=0
flag=1
while flag:
    flag=0
    index=0
    bef=0
    while index < len(listS):
        if index == 0:
            bef = listS[index]
        else:
            if bef == "#":
                if listS[index] == ".":
                    listS[index-1]="."
                    flag=1
                    count+=1
            bef = listS[index]
        index+=1
listS2 = list(inputS)
count2 = 0
flag = 1
while flag:
    flag = 0
    index = 0
    bef = 0
    while index < len(listS2):
        if index == 0:
            bef = listS2[index]
        else:
            if bef == "#":
                if listS2[index] == ".":
                    listS2[index] = "#"
                    flag = 1
                    count2 += 1
            bef = listS2[index]
        index += 1
print(min(count, count2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=10**10
for i in range(n):
    cost_w=s[:i+1].count("#")
    cost_b=s[i+1:].count(".")
    print(s[:i+1],s[i:])
    ans=min(ans,cost_w+cost_b)
print(ans)

Submission status: Wrong Answer

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

sl = list(s) + ['e']

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

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
s = list(input())+ [' ']
s = s
cnt = 0

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c=0
for i in range(N):
    if S[i]=='#':
        c=S[i:].count('.')
        break
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if "." in s:
    a = [i for i, x in enumerate(s) if x == '.'][-1]
    ans1 = s[:a].count("#")
else:
    ans1 = 0
if "#" in s:
    b = [i for i, x in enumerate(s) if x == '#'][0]
    ans2 = s[b:].count(".")
else:
    ans2 = 0
print(min(ans1, ans2))

Submission status: Wrong Answer

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

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

f = 0
res = 0
for i in s:
    if f == 1 and i==".":
        res += 1
    if i=="#":
        f = 1
else:
    print(res)

Submission status: Wrong Answer

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

List = [i for i in range(N) if S[i] == '#']
if List != []:
    idx = min(List)
    print(S[idx + 1:].count('.'))
else:
    print(0)

Submission status: Wrong Answer

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

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

print(S[cnt:].count('#'))

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

for i in range(n-1):
    if T[i] == '#' and T[i+1] == '.':
        tmp += 1
        T[i] = '.'

print(min(cnt,tmp))

Submission status: Wrong Answer

Solution code:
stones = [raw_input() for i in range(2)][1]
if "#" not in stones:
    print 0
else:
    counter = 0
    for i in stones[1:]:
        if i == ".":
            counter += 1
    print(counter)

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]
ans1 = ss.count(".")
ans2 = ss.count("#")
print(min(ans1,ans2))

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 = '.'

print(cnt)

Submission status: Wrong Answer

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

S = S + "#"

# is black, . is white
seq_black = 0
seq_white = 0
ans = 0
for idx, s in enumerate(S):
    if idx == 0:
        former = s
        if s == "#":
            seq_black += 1
    else:
        if s == "#":
            if seq_white > 0:
                ans += min(seq_black, seq_white)
                seq_black = 0
                seq_white = 0
                
            if former == s:
                seq_black += 1
            else:
                seq_black = 1
            
        else:
            # white
            if seq_black > 0:
                seq_white += 1
                
        former = s
print(ans)

Submission status: Wrong Answer

Solution code:
import re

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

ss = re.findall('#\.', S)

print(len(ss))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
# white:'.' , black:'#'
for i in range(n):
  if s[i] == '#':
    start = i
    break
else:
  start = n
ans = 0
for i in range(start, n):
  if s[i] == '.':
    ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(1, n + 1):
  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 = input()

num_sharp = 0
tmp_sharp = 0
for s in S:
    if s == ".":
        num_sharp += tmp_sharp
        tmp_sharp = 0
    else:
        tmp_sharp += 1

num_sharp2 = 0
tmp_sharp = 0
for s in reversed(S):
    if s == "#": # #-> .
        num_sharp2 += tmp_sharp
        tmp_sharp = 0
    else:
        tmp_sharp += 1

out = min(num_sharp, num_sharp2)
print(out)

Submission status: Wrong Answer

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

flag = False
white = 0

for s in S:
    if s == "#":
        flag = True
    if flag:
        if s == ".":
            white += 1

flag = False
black = 0

for s in S[::-1]:
    if s == ".":
        flag = True
    if flag:
        if s == "#":
            black += 1

ans = min(white,black)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = S.count('#.')
print(cnt)

Submission status: Wrong Answer

Solution code:
def ans():
  from itertools import groupby
  N = int(input())
  S = input()
  b = 0
  w = 0
  for k, v in groupby(S):
    v = len(list(v))
    if k == "#":
      b += v
    else:
      w += v
  print(min(b,w))
ans()

Submission status: Wrong Answer

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


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
try:
    first_black = S.index('#')
    target = S[first_black:]
    print(target.count('.'))
except ValueError:
    print(0)

Submission status: Wrong Answer

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

ans = 0
frag = False
for s in S:
    if s == '#':
        frag = True
    if frag and s == '.':
        ans += 1
print(ans)

Submission status: Wrong Answer

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


count1 = 0
found = False
for ss in s:
    if found:
        if ss == '.':
            print('n1')
            count1 += 1
        else:
            print('n2')
            pass
    else:
        if ss == '.':
            print('n3')
            pass
        else:
            print('n4')
            found = True



count2 = 0
found = False
for ss in s[::-1]:
    if found:
        if ss == '#':
            print('p1')
            count2 += 1
        else:
            print('p2')
            pass
    else:
        if ss == '#':
            print('p3')
            pass
        else:
            print('p4')
            found = True


print(min(count1, count2))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def kari():
    N = list(map(int, input().split()))
    A, B = map(int, input().split())

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

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

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

    print(min(ans, ans_2))




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
B = 0
W = 0
for i in range(N):
  if S[i] == '.':
    W += 1
  else:
    B += 1
print(min(B,W))

Submission status: Wrong Answer

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

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

turn_stones = 0
count_start = False

for i in range(trial_num):
    if(count_start == False):
        if(stones[i] == "#"):
            count_start = True
    else:
        if(stones[i] == "."):
            turn_stones += 1

print(turn_stones)

Submission status: Wrong Answer

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

lsts=list(s)

ans=0

for i in range(n-1):
    if lsts[i]=="#":
        if lsts[i+1]==".":
            ans+=1

print(ans)

Submission status: Wrong Answer

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

flag = False
ans = 0

for i in range(len(S)) :
    if flag :
        if S[i] == '.' :
            ans += 1
    if S[i] == '#' :
        flag = True

print(ans)

Submission status: Wrong Answer

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

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

print ans

Submission status: Wrong Answer

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

wc=0
for s in S:#白のみ連続の個数
    if s==".":
        break
    wc+=1

bc=0
for s in S[::-1]:#黒のみ連続の個数
    if s=="#":
        break
    bc+=1

if bc==0:
    print(min(S[wc:].count('.'),S.count('#')))
else:
    print(min(S[wc:].count('.'),S[:-bc].count('#')))

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(s[k:N+1].count("."))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0
S = ""


def set_inputs():
    global N, S
    N = get_int()
    S = get_str()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    s = "".join(itertools.dropwhile(lambda c: c == ".", S))
    black = []
    white = []
    count = 0
    prev = "#"
    for c in s:
        if c == prev:
            count += 1
        else:
            if prev == "#":
                black.append(count)
            else:
                white.append(count)
            prev = c
            count = 1
    if prev == "#":
        black.append(count)
    else:
        white.append(count)
    ans = 0
    for i in range(len(white)):
        count = min(black[i], white[i])
        if i + 1 < len(black):
            count = min(count, black[i + 1])
        ans += count
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = input()
pt = S.find("#")
ct = 0
if pt == -1:
    print(0)
else:
    ct = Counter(S[pt:])
    print(min(ct["."], N-pt-ct["."]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input()
s = [x for x in input()]
count = 0

for i in range(len(s)-1):
    if(s[i] == "#" and s[i+1] == "."):
        s[i+1] = "#"
        count = count + 1

print(count)

Submission status: Wrong Answer

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

l_1 = ['#' for i in range(N)]
t = 0
for i in range(N):
    if l_1[i]==S[i]:
        t+=1
print(min(t,N-t))

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
s=input()
black=0
write=s.count(".")
koho=deque([])
for i in s:
    if i==".":
        write-=1
    else:
        black+=1
    koho.append(write+black)
print(min(koho))

Submission status: Wrong Answer

Solution code:
N = input()
stone = input()
 
 
for i in range(len(stone) - 1):
  if stone[i] == '#' and stone[i+1] == '.':
    cnt_b = 0
    cnt_w = 0
    for s in stone[i:]:
      if s == '.':
        cnt_w += 1
      else:
        cnt_b += 1
        
    print(min(cnt_b, cnt_w))
    exit()
 
print('0')

Submission status: Wrong Answer

Solution code:
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

n = int(input())
s = input()
b = [0]
w = [0]
for i in range(n):
    bt = b[i]
    wt = w[i]
    if s[i] == "#":
        bt += 1
    else:
        wt +=1
    b.append(bt)
    w.append(wt)

cost = 1000000000000

for i in range(1,n+1):
    temp = 0
    temp += b[i]
    temp += w[-1]-w[i]

    # print(i)
    # print(b[i]-b[1])
    # print(w[-1]-w[i])

    if cost > temp:
        cost = temp
    # print(cost)
    # print("*********")


# print(b)
# print(w)

print(cost)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
num = -1
bl = 0
for i in range(n):
    if s[i] == "#":
        if bl == 0:
            num = i
        bl += 1
if num >= 0 and bl > n - num - bl:
    print(n-num-bl)
else:
    print(bl)

Submission status: Wrong Answer

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

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 = 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 = '#'

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S.count('.') < S.count('#'):
  print(S.count('.'))
else:
  print(S.count('#'))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
s2=s[:]
s2.reverse()
c=0
for i in range(len(s)):
  a=s[i]
  if a=='#':
    if i!=len(s)-1 and s[i+1]=='.':
      s[i+1]='#'
      c+=1
c2=0
for i in range(len(s2)):
  a=s2[i]
  if a=='.':
    if i!=len(s2)-1 and s2[i+1]=='#':
      s2[i+1]='.'
      c2+=1
print(min(c,c2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [1 if c == '#' else 0 for c in input()]
b_idx = len(S) - 1
for i in range(len(S)):
    if S[i] == 1:
        b_idx = i
        break

w_idx = 0
for i in range(len(S)):
    if S[-(i + 1)] == 0:
        w_idx = len(S) - (i + 1)
        break
w_idx += 1

res = sum(S[b_idx:w_idx])
length = max(0, (w_idx - b_idx))
print(min(res, length - res))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
fK = N
ansSK = 0
ansSS = 0
for i in range(N):
    if S[i] == '#':
        fK = i
        break
for j in range(fK,N):
    if S[j] == '.':
        ansSK += 1
    else:
        ansSS += 1
print(min(ansSK,ansSS))

Submission status: Wrong Answer

Solution code:
N  = int(input())
S = input()
black = S.count("#")
white = N - black
if black == 0 or white == 0:
    print(0)
else:
    if S[-1] == "#":
        black -= 1
    if S[0] == ".":
        white -=1
    print(min(black, white))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = N
for i in range(N+1):
    if i == 0:
        cnt = min(S.count('#'), cnt)
    elif i == N+1:
        cnt = min(S.count('.'), cnt)
    else:
        cnt = min(S[:i].count('#') + S[i:].count('.'), cnt)
print(cnt)

Submission status: Wrong Answer

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

white = S.count(".")
black = N - white
ans = 0

if white > black:
  ans = black
  S_reverse = S[::-1]
  for s in S_reverse:
    if s == "#":
      ans -= 1
    else:
      break
else:
  ans = white
  for s in S:
    if s == ".":
      ans -= 1
    else:
      break

print(ans)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

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
if h<=b:
    print(h)
else:
    print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
d = n - s[::-1].find('.') - 1
c = s[:d].count('#')
d2 = s.find('#')
c2 = s[d2:].count('.')
print(min(c, c2))

Submission status: Wrong Answer

Solution code:
#C - Stones
n = int(input())
s = list(input())
isFound = False
cnt = 0

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

Submission status: Wrong Answer

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

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

if k == n:
    print(0)
else :
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = s.find("#")
b = s.find(".")
#print(a)
if a == -1 or b == -1:
    print(0)
else:
    print(min(s[a:].count("."),s[:b+2].count("#")))

Submission status: Wrong Answer

Solution code:
from sys import exit
N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
white = False
ans0=0
ans1=0
for i in range(len(S)-1,-1,-1):
    if(S[i] == "."):
        white = True
    elif(white and S[i] == "#"):
        ans0+=1
black = False
for i in range(len(S)):
    if(S[i] == "#"):
        black = True
    elif(black and S[i] == "."):
        ans1+=1
print(min(ans0,ans1))

Submission status: Wrong Answer

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

print(min(S.count("#"), S[S.find("#") + 1:].count(".")))

Submission status: Wrong Answer

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

S = S.replace('#.', '*')
print(S.count('*'))

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnta = s.count("#")
cntb = s.count(".")
ans = min(cnta,cntb)
f = 0
cnt = 0
for i in range(N):
	if f == 0 and s[i] == ".":
		f = 1
	if f == 1 and s[i] == "#":
		cnt += 1
else:
	ans = min(ans,N-i+1)
	
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

Submission status: Wrong Answer

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

replace_dot_result = 0
replace_sharp_result = 0
for char in s[1:]:
    if char == ".":
        replace_dot_result += 1

for char in s:
    if char == "#":
        replace_sharp_result += 1

print(min(replace_dot_result, replace_sharp_result))

Submission status: Wrong Answer

Solution code:

n = int(input())

s = input()

idx = s.find(".#")

if idx != -1:
  left = s[:idx+1].count("#")
  right = s[idx+1:].count(".")
  print(left+right)
else:
  print(0)

Submission status: Wrong Answer

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

ans = 0
start = len(s)
i = 0
while(i<len(s)):
    if(s[i]=="#"):
        start = i
        i = len(s)
    else:
        i += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = 0
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 = list(input())
count = 0

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]

n = readInt()
s = sys.stdin.readline().strip()

w = 0
wbb = 0
b = 0
for i, c in enumerate(s):
    w += int(c == '.')
    wbb += int(c == '.') if b == 0 else 0
    b += int(c == '#')

ret = min(b, w - wbb)
print(ret)

Submission status: Wrong Answer

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

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

need = n
for i in range(n):
    if s[i] == "#":
        need = 0
        for j in range(i,n):
            if s[j] == ".":
                need += 1
        break

black = 0
for i in range(n):
    if s[i] == "#":
        black += 1

print(min(need,black))

Submission status: Wrong Answer

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

flag = False
count = 0
for i in list(S):
    if(i == '#'):
       if(flag != True):
           flag = True
    else:
        if(flag):
            count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
S = input()
if not '#' in S:
    print(0)
else:
    ans = S.count('.')
    num = bisect.bisect_left(S, '#')
    print(ans-num)

Submission status: Wrong Answer

Solution code:
# Tenka1 Programmer Beginner Contest 2019
# https://atcoder.jp/contests/tenka1-2019-beginner
# 
# 

import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main(N, S):
    lc = 0
    rc = 0
    for i in range(N):
        if S[i] == '.':
            lc += 1
        else:
            break
    for i in range(N):
        if S[N-1-i] == '#':
            rc += 1
        else:
            break
    wc = 0
    bc = 0
    for i in range(lc, N-rc):
        if S[i] == '.':
            wc += 1
        else:
            bc += 1
    ans = min(wc, bc)
    print(ans)

N = i2n()
S = i2s()
main(N, S)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
white = S.count(".")
black = S.count("#")
print(N-max(white,black))

Submission status: Wrong Answer

Solution code:
"""
python3 a.py < input.txt
"""
import math
import itertools as it
import heapq
"""
N=int(input())
S=input()
K=int(input())

sk=S[K-1]
O=[]
for i in range(0,N):
    if S[i] == sk:
        O.append(S[i])
    else:
        O.append("*")

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())  # 数値入力
str = list(input())  # 一文字ずつ格納
newstr = []
for i in range(len(str)):
    if str[i] == "#":
        newstr = str[i:]
        break

if len(newstr) == 0:
    print("0")
else:
    print(min(newstr.count("."), newstr.count("#")))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())	
s2 = s[:]

cnt1=0
for i in range(len(s) -1 ):
    if(s[i] == "#" and s[i + 1] == "."):
        s[i+1]="#"
        cnt1 +=1
cnt2=0

for i in range(len(s2) -1 ):
    if(s2[n-i-1] == "." and s2[n-i- 2] == "#"):
        s2[n-i-2]="."
        cnt2 +=1

print(min(cnt1,cnt2))