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

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

    if i == n-1:
        d = i

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

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

print(min((count, n-d-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+1].count("."), S[head_dot:tail_hash+1].count("#"))
    return ans

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
for i in range(0,n) :
    if s[i] == '.' :
        continue
    elif s[i] == '#' :
        break
s = s[i:n-1]
x = s.count('#')
y = s.count('.')
print(min(x,y))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

white = 0
black = 0

first_black_index = 0

while S[first_black_index] == ".":
  first_black_index += 1
  if first_black_index == N:
    print(0)
    break
if first_black_index != N:
  S = S[first_black_index:N+1]

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

  print(min(white,black))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    s2 = s[first_black+1:]
    white_to_black = s2.count('.')
    print(min(s.count('#.'), s2.count('.')))

Submission status: Wrong Answer

Solution code:
N = int(input())
stones = input()
pre_word = stones[0]
stones_list =[]
counter = 0

for i in range(N):
    stones_list.append(stones[i])

for i in range(N):
    present_word = stones_list[i]
    if pre_word == '#' and present_word =='.':
        counter += 1
    pre_word = stones_list[i]
print(counter)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = long(sys.stdin.readline())
    S = sys.stdin.readline().lstrip('.')
    numA = S.count('.')
    numB = S.count('#')
    print(min(numA, numB))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

# . : white
# # : black
# no '#.' sequence

# a list that represents no of stone of the color interested up to that indices
nwhite, nblack = [], []

cur_nwhite, cur_nblack = 0, 0
for i, c in enumerate(S):
    if c == '.':
        cur_nwhite += 1
    else:
        cur_nblack += 1

    nwhite.append(cur_nwhite)
    nblack.append(cur_nblack)

if cur_nwhite == 0 or cur_nblack == 0:
    print(0)

else:
    # indices of start of the sequence of black stones
    black = []
    i = 0
    flag = False

    while(i<N):
        if S[i] == '#':
            if not flag:
                black.append(i)
                flag = True
        
        else:
            flag = False
        
        i += 1

    # print('white: ',nwhite)
    # print('black: ', nblack)
    # print('i-black: ',black)

    ans = 2 * (10 ** 5) + 1

    # set a index that starts sequence of black(#)
    for i in black:

        curans = 0

        # then turn over all black(#) left to it
        if i > 0:
            curans = nblack[i-1]

        # then turn over all white(.) right to it    
        curans += (cur_nwhite - nwhite[i])

        ans = min(ans, curans)

    print(ans)

Submission status: Wrong Answer

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

count_s = 0
count_d = 0
for i in range(1,n):
    if s[-i] == '#':
        count_s += 1
    else:
        break

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

s = s[count_d:n-count_s]
print(s)
sharp_num = s.count('#')
dot_num = s.count('.')

print(min(sharp_num,dot_num) + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
f = S.find('#')
black = S.count('#',0,S.rfind('.'))
white = S.count('.',f)
if black < white:
    print(black)
else:
    print(white)

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
#print(N,S)

if not "#" in S or not "." in S:
  print(0)
else:
  print(S.count("."))

Submission status: Wrong Answer

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

a = 0
b = 0

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


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

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()
print(b.count('#.'))

Submission status: Wrong Answer

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

num_w = 0
num_b = 0
while num_w <= N - 1 and S[num_w] == '.':
  num_w += 1
if num_w == N:
  print(0)
  exit()
while num_b <= N - 1 and S[N - 1 - num_b] == '#':
  num_b += 1
if num_b == N:
  print(0)
  exit()
print(num_w, num_b)
target = S[num_w: N - num_b]
print(min(target.count('.'), target.count('#')))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = S[::-1]
 
a = 0
i = 0
state = ""
w_count = 0
b_count = 0
for s in S:
  if s == ".":
    w_count += 1
    if state == "b":
      if w_count > b_count:
         a += b_count
      else:
         a+= w_count
      w_count = 0
      b_count = 0
    state = "w"
  else:
    b_count += 1
    state = "b"
 
print(a)

Submission status: Wrong Answer

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

Bflag = False
countA = 0
countB = 0
for i in range(N):
  if S[i] == '#':
    Bflag = True
    if i != N-1:
      countB = countB + 1
  elif Bflag is True:
    countA = countA + 1

if countA < countB:
  print(countA)
else:
  print(countB)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
ans = stdin.readline().rstrip()
count = 0
right = 0
for left in range(0,len(ans)):
    right = left+1
    if left == len(ans)-1:
        break
    if ans[left] == '.':
        while(right < N and ans[right] == '#'):
            count += 1
            right += 1
        left = right
        if left == right:
            right += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

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

score1 = 0
score2 = 0
length = 1
check = S[0]
A = []
B = []
flag = 0

for i in range(N-1):
    if S[i] == S[i+1]:
        length += 1
    else:
        A.append(length)
        length = 1

if length != 1:
    A.append(length)

if len(A) != 0:
    if S[-1] != S[-2]:
        A.append(1)

if len(A) <= 1:
    print(0)
    sys.exit()

if S[0] == ".":
    A.pop(0)

if S[len(S)-1] == "#":
    A.pop(-1)

if len(A) == 0:
    print(0)
    sys.exit()

for i in range(len(A)):
    if i % 2 == 0:
        score1 += A[i]
    else:
        score2 += A[i]

ans = min(score1,score2)

if S[0] == "#":
    score3 = A[0] + score2 - A[1]
    ans = min(ans,score3)

if S[0] == ".":
    score4 = A[len(A)-1] + score1 - A[len(A)-2]
    ans = min(ans,score4)

print(ans)

Submission status: Wrong Answer

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

if len(S) == 0:
	print(0)
else:
	for n in range(N):
		if S[n:n+2] == "#." :
			M = n+1
			break
		else:
			M = len(S)+1
	for j in range(N):
		if S[-(j+1)] == "#":
			B_end += 1
		if S[-(j+1)] == ".":
			break
	for k in range(N):
		if S[-(k+2):-k] == "#.":
			Mdual = -k-1
			break
		else:
			Mdual = len(S) + 1
	WB = S[M:].count(".")
	BW = max(1, S[:Mdual].count("#"))
	print(min(WB , BW))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
sc=0
tc=0
ans=0
for i in range(N):
    if(S[i]=='#'):
        sc+=1
    else:
        tc+=1

if(sc>tc):
    print(str(tc))
else:
    print(str(sc))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
cd = 0 ; dh = 0; ok = False
for i in range(0 , len(s)):
  if(s[i] == '#'):
    ok = True; dh += 1;
  if(ok and s[i] == '.'):
    cd += 1
sr = s[::-1]
xd = 0 ; xr = 0
for i in range(0 , len(sr)):
  if(sr[i] == '#'):
    xd += 1
  else:
    break
print(min(cd , dh - xd))

Submission status: Wrong Answer

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

print(s.count("#.") + s.count("##.."))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sharp_num =[]
dot_num = []

search = '#'
count = 0

for c in S:
    if search == '#':
        if c == search:
            count += 1
        else:
            sharp_num.append(count)
            count = 1
            search = '.'
    else:
        if c == search:
            count += 1
        else:
            dot_num.append(count)
            count = 1
            search = '#'
            
if search == '#':
    sharp_num.append(count)
    dot_num.append(0)
else:
    dot_num.append(count)

total = 0
for i in range(len(sharp_num)):
    total += min(sharp_num[i],dot_num[i])

print(total)

Submission status: Wrong Answer

Solution code:
import sys

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

num = int(a[0])
haichi = a[1]
count_list = []

# 左側を全部白にする手数 (= 左側の黒の数)
split_left_count = [sum([x == '#' for x in haichi[:i]]) for i, x in enumerate(haichi)]

# 右側を全部黒にする手数 (= 右側の白の数)
split_right_count = [sum([x == '.' for x in haichi[i:]]) for i, x in enumerate(haichi)]

for i in range(num):
    count_list.append(split_left_count[i]+split_right_count[i])

print(min(count_list))

Submission status: Wrong Answer

Solution code:
num = int(input())
stone = list(input())

count = 0
# 多分、これだと最小値ではない
# for i in range(num - 1):
#     if stone[i] == "#" and stone[i + 1] == ".":
#         if i == 0:
#             stone[i] = "."
#         else:
#             stone[i + 1] = "#"
#         count += 1

# 最終状態としては、全部黒、全部白、白が続いて残り全部黒、しかない
for i in range(num - 1):
    if stone[i] == ".":
        continue
    else:
        # 黒が出たらそこ以降を全部黒か白にするしかない
        # 例外：
        if stone[i:].count(".") > stone[i:].count("#"):
            count = stone[i:].count("#")
        else:
            count = stone[i:].count(".")
        break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    s = s.rsplit('.#', 1)[0] + '.#' if '.#' in s else  s
    ptn = re.search(re.compile('\.#+?$'), s)
    if ptn:
        s = s[:ptn.start()]
    print(s)
    print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

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

res = 0
index = 0
if s[0] == ".":
    for i in range(1, len(s)):
        if s[i] != s[i - 1]:
            index = i
            break
        index = len(s)
for i in range(index, len(s)):
    if s[i] == ".":
        res += 1

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s.lstrip(".").rstrip("#")
count = s.count(".")

if count < n - count:
    print(count)
else:
    print(n - count)

Submission status: Wrong Answer

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

S = input()

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

ans = 0
for r in result:
    size = len(r)
    if size == 2:
        ans += 1
    else:
        Bsize = r.count('#')
        if Bsize < size - Bsize:
            ans += Bsize
        else:
            ans += size - Bsize
print(ans)

Submission status: Wrong Answer

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

white = 0
black = 0

first_black_index = 0

while S[first_black_index] == ".":
  first_black_index += 1
  if first_black_index == N:
    print(0)
    break
if first_black_index != N:
  S = S[first_black_index:N+1]
  print(S)

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

  print(min(white,black))

Submission status: Wrong Answer

Solution code:
n = input()
s = input()
s_list = list(s)
nmone = int(n) - 1
changednum = 0
for num in range(nmone):
  nump = num + 1
  if s_list[num] == "#":
  #if s_list[num] == "#" and s_list[nump] == ".":
    s_list[nump] = "#"
    changednum += 1
  else:
    pass
#sed = "".join(s_list)
print(changednum)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())+['A']

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [1 if x == '.'  else 0 for x in list(input())]

cost = sum(S)
min_cost = cost 

for i in range(1, N, 1):
    if S[i-1] == 0:
        cost += 1
    else:
        cost -= 1

    if min_cost > cost:
        min_cost = cost
        
print(min_cost)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())
 
try:
    i=s.index("#")
except:
    i=0
 
print min(s[i:].count("."), s.count("#"))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


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

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



S_black_list=list(S)
S_white_list=list(S)

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

to_white_counter=0

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

'''
print(white_count)
print(black_count)
print(counter)
print(to_black_counter)
print(to_white_counter)
'''
print(int(min(white_count, black_count, counter, to_black_counter, to_white_counter)))


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

S_black_list=list(S)

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


        

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li = []
for i in range(n):
    if s[i] == "#":
        li.append(i)
li.append(len(s))
sum = 0
if len(li) == 1:
    print(0)
else:
    for i in range(len(li)-1):
        diff = li[i+1] - li[i] - 1
        if diff >= i+1:
            sum = i+1
        else:
            sum += diff
    print(sum)

Submission status: Wrong Answer

Solution code:
SIRO = '.'
KURO = '#'
N = int(input())
S = input()
sLst1 = []
sLst2 = []
for i in S:
    sLst1.append(i)
    sLst2.append(i)
ans = 0
kCnt = S.count(KURO)
sCnt = S.count(SIRO)
if kCnt > sCnt:
    for i in range(0, N - 1):
        if sLst1[i] == KURO:
            if sLst1[i + 1] == SIRO:
                sLst1[i + 1] = KURO
                ans += 1
elif sCnt> kCnt:
    for i in range(N - 1, 0, -1):
        if sLst2[i] == SIRO:
            if sLst2[i - 1] == KURO:
                sLst2[i - 1] = SIRO
                ans += 1
else:
    ans1 = 0
    ans2 = 0
    for i in range(0, N - 1):
        if sLst1[i] == KURO:
            if sLst1[i + 1] == SIRO:
                sLst1[i + 1] = KURO
                ans1 += 1
    for i in range(N - 1, 0, -1):
        if sLst2[i] == SIRO:
            if sLst2[i - 1] == KURO:
                sLst2[i - 1] = SIRO
                ans2 += 1
    ans = min(ans1, ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

flag = 0
count = 0

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

Submission status: Wrong Answer

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

b = 0
w = 0
ans = 0
for s_ in s:
  if w == 0 and s_ == "#":
    b = b + 1
  elif w > 0 and s_ == "#":
    ans = ans + min(b,w)
    b = 1
    w = 0
  if b > 0 and s_ == ".":
    w = w + 1
if w > 0:
  ans = ans + min (b,w)

print(ans)

Submission status: Wrong Answer

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

#all白
s1=len([w for w in s if w=="#"])

#all黒
s2=len([w for w in s if w!="#"])

#右1黒
if s[-1]=="#":
  s3=min(len([w for w in s[:-1] if w=="#"]),len([w for w in s[:-1] if w!="#"]))
else:
  s3=min(len([w for w in s[:-1] if w=="#"]),len([w for w in s[:-1] if w!="#"]))+1

print(min([s1,s2,s3]))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop


def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))
INF = 1 << 29


def runLength(in_str):
    kukan = 1
    start = 0
    ret = []
    for i in range(1,len(in_str)):
        if in_str[i-1]!=in_str[i]:
            ret.append([in_str[i-1],kukan,start])
            start = i
            kukan=0
        kukan+=1
    ret.append([in_str[-1],kukan,start])
    return ret

N = int_raw()
S= input()

dp = {}

def rec(ss):
    return 0

def main():
    global S
    ans = INF
    numB = [0]*len(S)
    leftMostW = -1
    
    for i in range(len(S)):
        if i > 0:
            numB[i]=numB[i-1]
        if S[i]=="#":
            numB[i]+=1
    if numB[len(S)-1]==0 or numB[len(S)-1]==len(S):
        return 0        
    for i in range(len(S)):
        buf = numB[i]+len(S)-1-i-(numB[len(S)-1]-numB[i])
        ans = min(ans, buf)
    
    return ans



print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if "#" in s:
    k = s.index("#")
    print(0 if k == n-1 else min(s[k+1:].count("."),s[k+1:].count("#")))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
inp =input()
li = list(input())
ch = 0
cou = 0
fff = 0
ina = ''
aa = 1
m = []


lin = len(li) - 1
for n in range(len(li)):
    if n == lin:
        break
    else:
        if li[n] == li[n+1]:
            aa += 1

        else:
            m.append(aa)
            aa = 1 
m.append(aa)
if li[0] == '.':
    m.pop(0)
if li[-1] == '#':
    m.pop(-1)

shape =0
dotto = 0
for ww in range(len(m)):
    if ww % 2 == 0:
        shape += m[ww]
    else:
        dotto += m[ww]
if shape >= dotto:
    print(dotto)
else:
    print(shape)

Submission status: Wrong Answer

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

BLACK = '#'
WHITE = '.'

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

if S[len(S) - 2] == BLACK and S[len(S) - 1] == WHITE:
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
num = int(input())
line = input()
result = 0
flg = 0
for i in range(num):
    if line[i] == "#":
        flg = 1
        continue
    if line[i] == "." and flg == 1:
        result += 1
        
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
blacknum = []
whitenum = []
cnt = 0
now = 0
blackcnt = 0
whitecnt = 0

for i in range(N):
    if now == 0 and S[i] == '#':
        whitenum.append(whitecnt)
        blackcnt += 1
        now = 1
    elif now == 1 and S[i] == '.':
        blacknum.append(blackcnt)
        whitecnt += 1
        now = 0
    elif now == 0 and S[i] == '.':
        whitecnt += 1
    else:
        blackcnt += 1

if now == 0:
    whitenum.append(whitecnt)
else:
    blacknum.append(blackcnt)
if len(whitenum) == len(blacknum):
    whitenum.append(whitecnt)

ans = whitecnt
for i in range(len(blacknum)):
    tmp = blacknum[i] + (whitenum[-1] - whitenum[i+1])
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if all([s[i]=="#" for i in range(n)]):
    print(0)
    exit()
if all([s[i]=="." for i in range(n)]):
    print(0)
    exit()
try:
    a=s[::-1].index("#")
    b=s.index("#")
    c=s[::-1].index(".")
except:a=b=0
print(b,c,n)
if b+c==n:
    print(0)
    exit()
count=0
for i in range(b+1,n-a):
    if s[i]=="#":count+=1
print(min(count,s.count("#"),s.count(".")))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
s=[]
kuro = S.count("#")
shiro = S.count(".")
Slist =list(S)
if Slist[N-1] == ".":
	s=S.split("#")
	if (len(s)) == 2:
		print(1)
	else:
		if Slist[N-1] == "#":
			print(min(kuro-1,shiro))
		else:
			print(min(kuro,shiro))
		
else:
	if Slist[N-1] == "#":
		print(min(kuro-1,shiro))
	else:
		print(min(kuro,shiro))

Submission status: Wrong Answer

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

ans = n
for i in range(n):
    num = s[:i].count('#') + s[i:].count('.')
    if num < ans:
        ans = num
print(ans)

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 grouping(N, S):
    g = []
    s = S[0]
    c = 1
    for i in range(1, N):
        if S[i] == s:
            c += 1
        else:
            g.append((s, c))
            c = 1
            s = S[i]
    g.append((s, c))
    return g

def main(N, S):
    g = grouping(N, S)
    gl = len(g)
    l = 0
    r = gl - 1
    if g[l][0] == '.':
        l += 1
    if g[r][0] == '#':
        r -= 1
    if r - l < 1:
        print(0)
        return
    ll = [0]
    lr = [0]
    lc = 0
    for i in range(l, r, 2):
        ll.append(g[i][1] + ll[-1])
        lr.append(g[i+1][1] + lr[-1])
        lc += 1
    ans = N
    for i in range(lc):
        tl = ll[i]
        tr = lr[lc] - lr[i]
        ans = min(ans, tl + tr)
    print(ans)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
tmp1 = 0
tmp2 = 0
sharp = 0
dot = 0
sharp2 = 0
dot2 = 0
sharp3 = 0
dot3 = 0
for i in range(1, n+1):
    if s[-i] == "#":
        tmp1 += 1
    else:
        break
for i in range(1, n+1):
    if s[-i] == ".":
        tmp2 += 1
    else:
        break
#print(s[:n-tmp1])
#print(tmp1)
for i in s:
    if i == "#":
        sharp += 1
    if i == ".":
         dot += 1
for i in s[:n-tmp1]:
    if i == "#":
        sharp2 += 1
    if i == ".":
         dot2 += 1

for i in s[:n-tmp2]:
    if i == "#":
        sharp3 += 1
    if i == ".":
         dot3 += 1
print(min(sharp, dot, sharp2, dot2, sharp3, dot3))

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
if cnt1 < cnt2:
    print(cnt1)
else:
    print(cnt2)

Submission status: Wrong Answer

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

  ans = 10**15
  a = s.count(".")
  b = s.count("#")
  sharp = []
  dot = []
  tp = 1
  if a == n:
    print("0")
    exit()
  elif n == 1:
    print(b)
    exit()
  else:
    for i in range(n-1):

        if s[i] == s[i+1]:
           tp += 1
               
        if s[i] != s[i+1]:
            if s[i]==".":
                dot.append(tp)
                sharp.append(0)
            else:
                dot.append(0)
                sharp.append(tp)
            tp = 1
        if i == n-2:
           if s[i+1]==".":
                dot.append(tp)
                sharp.append(0)
           else:
                dot.append(0)
                sharp.append(tp)
           tp = 1
    
    e = len(sharp)
    ans = min(b-sharp[-1],a-dot[0])

    for i in range(e):
      if i%2 == 1 and i <= e-2:
       do = dot[i]+dot[i+1]
       sh = sharp[i]+sharp[i+1]
       sharpp = 0
       dotp = 0
       if not i in [0,e-1]:
        a += sh -do
        b += do- sh
        ans = min(ans,min(b-sharp[-1],a-dot[0]))
      
    #print(dot,sharp)     
    print(ans)
solve()

Submission status: Wrong Answer

Solution code:
size = int(input())
stone= str(input())
cnt=0
cnt2=0
cnt3=0
for i in range(size):
    if(stone[i]=="."):
        cnt+=1
    else:
        break
for i in range(size):
    if(stone[i]=="."):
        cnt2+=1
    else:
        cnt3+=1
        
if(stone[0]=="#"):
    print(cnt2)
else:
    if(cnt2-cnt<=cnt3):
        print(cnt2-cnt)
    else:
        print(cnt3)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += "-"
white = [0]
black = [0]
white_acc = 0
black_acc = 0
counter = 0
for i in range(n + 1):
    if s[i] == s[i - 1]:
        pass

    elif s[i - 1] == "#":
        black_acc += counter
        black += [black_acc]
        counter = 0
    elif s[i - 1] == ".":
        white_acc += counter
        white += [white_acc]
        counter = 0
    counter += 1
if len(black) + len(white) <= 3:
    print(0)
    exit()

last_white = white[len(white) - 1]
min_acc = 2 * 10 ** 5
if s[0] == "#":
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i])

else:
    for i in range(len(white) - 1):
        min_acc = min(min_acc, last_white - white[i] + black[i - 1])
print(min_acc)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = list(input())

tmp = S.count("#")
num = [0]*N
num_sharp = 0
num_peri = 0
for i in range(len(S)):
	if S[i] == "#":
		num_sharp += 1
	else:
		num_peri += 1
	num[i] = num_sharp + (len(S)-(i+1))-(tmp-num_sharp)
# print(num)
print(min(num))

Submission status: Wrong Answer

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

dp_dot = [0 for i in range(n)]
dp_hash = [0 for i in range(n)]

for i in range(1,n):
    if s[i]=='#':
        dp_hash[i] = min(dp_hash[i-1], dp_dot[i-1]) + 1
        dp_dot[i] = dp_dot[i-1]
    else:
        dp_dot[i] = min(dp_hash[i-1], dp_dot[i-1]) + 1
        dp_hash[i] = dp_hash[i-1]

print(min(dp_hash[n-1], dp_dot[n-1]))

Submission status: Wrong Answer

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

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

middle = S[1:-1]
white = middle.count('.')
black = middle.count('#')

if white < black:
  if S[-1] == '.':
    print(white+1)
  else:
    print(white)
else:
  if S[0] == '#':
    print(black+1)
  else:
    print(black)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())
if set(S) == {'#'} or set(S) == {'.'}:
    print(0)
    sys.exit()
first_b = S.index('#')
if S[-1] == '#':
    rev_first_w = S[::-1].index('.')
    b_count = S.count('#') - S[N-rev_first_w:].count('#')
else:
    b_count = S.count('#')
w_count = S[first_b:].count('.')
if b_count < w_count:
    print(b_count)
else:
    print(w_count)