Problem:


Score : 300 points

Problem Statement

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
#.#

Sample Output 1

1

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

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
 
n1 = S.count(".")
n2 = S.count("#")
n3 = N
for i in range (N):
    tco = S[:N].count("#") + S[N:].count(".")
    if n3 > tco:
        n3 = tco

print(min(n1,n2,n3))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
import bisect

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

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

    total_white = S.count('.')
    total_black = S.count('#')
    ans = min(total_white, total_black)
    rest_white = total_white

    current_ans = 0
    S += '#'  # 番兵
    black_count = 0
    white_count = 0
    for i in range(len(S)):
        if S[i] == '#':
            black_count += 1
            if white_count > 0:
                # consider
                tob = black_count - 1
                ans = min(ans, current_ans + white_count + rest_white, current_ans + tob + rest_white)
                current_ans += tob
                white_count = 0
                black_count = 1
        else:
            if black_count > 0:
                white_count += 1

            rest_white -= 1
    print(ans)


if __name__ == '__main__':
    main()

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
    firstB = N
    for i in range(len(S)):
        if i > 0:
            numB[i]=numB[i-1]
        if S[i]=="#":
            numB[i]+=1
            
    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 = 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] == "#" and s_list[nump] == ".":
    changednum += 1
  else:
    pass
print(changednum)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
flag = 0
location1 = 0
location2 = 0
for i in range(n):
    if s[i] == '#':
        location1 = i
        flag = 1
        break

count1 = s[location1:n].count('.')

s = s[::-1]
i = 0

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

count2 = s[location2:n].count('#')

if flag == 0:
    print(0)
else:
    print(min(count1, count2))

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)
  elif s[id:N-1].count('.') == 0:
    print(0)
  else:
    s_a = s[0:id]
    s_b = s[id+1:N-1]
    a = s_a.count('#')
    b = s_b.count('.')
    if a > b:
      print(b)
    else:
      print(a)
else:
  print(0)

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]=='.':
    S[i]='#'
    c+=1
  elif S[i-1]=='.'and S[i]=='#':
    f=False

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = S[::-1]
S += 'X'
tmps = 0; tmpd = 0
sharp = []; dot = []
if '#' not in list(S) or '.' not in list(S):
    print(0)
else:
    for i in range(N):
        if S[i] == '#':
            tmps += 1
            if S[i+1] != '#':
                sharp.append(tmps)
                tmps = 0
        if S[i] == '.':
            tmpd += 1
            if S[i+1] != '.':
                dot.append(tmpd)
                tmpd = 0
    if S[0] == '#':
        del sharp[0]
        ans = sum(sharp)
    else:
        del sharp[0]
        ans = sum(sharp) + dot[0]
    print(ans)

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+1, N-w):
    if S[i] == '.':
      a += 1
    else:
      b += 1
  print(min(a, b))

Submission status: Wrong Answer

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

bcounts = [0 for _ in range(len(S))]
wcounts = [0 for _ in range(len(S))]
cs = 0
for i in range(len(S)):
    if S[i] == '#':
        cs += 1
    bcounts[i] = cs
cs = 0
for i in reversed(range(len(S))):
    if S[i] == '.':
        cs += 1
    wcounts[i] = cs

INF = float('inf')
ans = INF
for i in range(len(S) - 1):
    if S[i] == '#' and S[i + 1] == '.':
        # 次の黒を超えたところの wcounts
        ni = i + 1
        while ni < len(S) and S[ni] == '.':
            ni += 1
        while ni < len(S) and S[ni] == '#':
            ni += 1
        if ni < len(S):
            wc = wcounts[ni]
        else:
            if wcounts[-1] == '.':
                wc = 1
            else:
                wc = 0
        ans = min(ans, bcounts[i] + wc)

print(0 if ans == INF else ans)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
count = 0
m = -1
for x in range(n):
	if s[x] == "#":
		m = x
		break
if m != -1:
	for u in range(m,n):
	    if s[u] == ".":
		    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
#!/snap/bin/pypy3

def sharpcounter(string):
    for i, char in enumerate(string):
        if char != '#':
            return i
    else:
        return len(string)


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

    count = 0
    tmp_sharp = 0
    for i, char in enumerate(S):
        if char == '#':
            tmp_sharp += 1
        else:
            if i + 1 < N and S[i+1] == '#':
                count += 1
                tmp_sharp += 1
            elif i + 1 == N:
                count += int(tmp_sharp > 0)
            else:
                count += min(tmp_sharp, sharpcounter(S[i+1:]) + 1)
                tmp_sharp = 0

    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a=0
b=0
d=0
flag=1

revS = S[::-1]

if S.find("#.") != -1:
    for i in revS:
        if i == "#":
            if flag==-1:
                a+=1


        else:
            b+=1
            flag=-1

    if a>b:
        print(b-d)
    else:
        print(a-d)

else:
    print(0)

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    S = input()
    w = S.count('.')
    b = S.count('#')
    ans = float('INF')
    for i in range(len(S) - 1):
        lb = S[:i].count('#')
        rw = S[i + 1:].count('.')
        ans = min(w, b, lb + rw, ans)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
p=0
count=0
ketu=0
a=0
d=0
#左から黒をカウントして、黒を返すだけで済むならそっちを採用する、
#そうでないなら特定の黒より右で、少ない方に応じて色を変える
#黒がシャープ白がドット
for i in range(N):
    if S[i]=='#':
        count=S[i:].count('#')
        p=i
        break
    else:
        pass
for i in range(p,N):
    if S[i]=='#':
        a=a+1
    else:
        break
S_reverse=S[::-1]
for i in range(N):
    if S_reverse[i]=='.':
        d=d+1
    else:
        break
for i in range(N):
    if S_reverse[i]=='#':
        ketu=ketu+1
    else:
        break

print(min(count-ketu,N-p-count,a+d))
#この後にケツからシャープ数えて引ける可能性もある
#白と黒の少ない方をとったつもり

Submission status: Wrong Answer

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

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

    ans = 0
    min_num = min(s.count(black), s.count(white))
    for i in range(len(s)):
        if needToChange(s, i):
            changeStone(s, i)
            ans += 1
    print(min(ans, min_num))

def needToChange(s, i):
    if i < 0 or len(s) - 2 < i:
        return False
    if s[i] == white:
        return False
    return s[i + 1] == white

def changeStone(s, i):
    if needToChangeBlackToWhite(s, i):
        s[i] = white
    else:
        s[i + 1] = black

def needToChangeBlackToWhite(s, i):
    white_length = getAWL(s, i + 1)
    black_length = getBBL(s, i)
    return white_length > black_length

def getAWL(s, i):
    res = 0
    for j in range(i, len(s)):
        if s[j] == black:
            return res
        res += 1
    return res

def getBBL(s, i):
    res = 0
    for j in range(0, i):
        if s[i - j] == white:
            return res
        res += 1
    return res

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
f,ans,b,w = 0,0,0,0
for i in s:
  if i == '#':
   
    b+=1
    f = 1
  else:
    if f == 1:
      w +=1
    
ans += min(b,w)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=2
a=[input() for i in range(n)]
N=int(a[0])
S=list(a[1])

kazuXD=0
flg=0
kazu=0
for i in range(N):
  if flg==0:
    if S[i]==".":
      kazu+=1
    else:
      flg=1

for i in range(kazu,N):
  if S[i]==".":
    S[i]="#"
    kazuXD+=1
geri=0
for i in range(N):
  if S[i]=="#":
    geri+=1

if geri>kazuXD:
  print("geri")
else:
  print("kazuXD")

Submission status: Wrong Answer

Solution code:
#import numpy as np
N = int(input())
S = input()

penals1 = []
tmp1 = 0
for s in S:
    if s == "#":
        tmp1 += 1
    penals1.append(tmp1)


penals2 = []
tmp2 = 0
for s in reversed(S):
    if s == ".":
        tmp2 += 1
    penals2.insert(0, tmp2)

penals = [penals2[0]] + [penals1[i] + penals2[i+1] for i in range(1, N-1)] + [penals1[N-1]]
out = min(penals)
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
count1=0
count2=0
for i in range(n):
  if s[i]=="#":
    count1=count1+1
  if s[i]==".":
    count2=count2+1
print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
siro = S.count(".")
kuro = S.count("#")
change_num = 0
if kuro < siro:
	change_num = kuro
elif kuro > siro:
	change_num = siro
else:
	# kuro == siro
	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:
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
  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 = input()
allblack = S.count('.')
allwhite = S.count('#')
firstblack = S.find('#')
ushiro = 1
while S[-ushiro] == '#':
    ushiro += 1
    if ushiro > N:
        break
ushiro -= 1
katamari = N - ushiro

if firstblack != -1:
    BlackToWhite = S[firstblack:katamari].count('#')
    #print(ushiro)
    #print(S[firstblack:katamari])
    WhiteToBlack = S[firstblack:katamari].count('.')
    lastblack = min(BlackToWhite, WhiteToBlack)
else:
    lastblack = 2 ^ 32
#print('allblack: ' + str(allblack))
#print('allwhite: ' + str(allwhite))
#print('lastblack: ' + str(lastblack))
print(min(allblack, allwhite, lastblack))

Submission status: Wrong Answer

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

b=0
w=0
for i in range(N):
	if S[i]=="#": b+=1
	else: w+=1
print min(b,w)

Submission status: Wrong Answer

Solution code:
stone=input()
color=input()
a=int(stone)
counter=0
black = 0
white = 0
xxx=[9999]
list=[]
for i in range(a):
    list.append(color[i])
for i in range(a):
    if list[i]=='#':
        xxx.append(i)
        black += 1
    if list[i]=='.':
       white += 1
if min(xxx)==9999:
    s=9999
else:
    s = min(xxx)
for k in range(s,a):
    if list[k]=='.' :
        counter = 1+ counter
if black > white:
    print(black)
else:
    if s==9999:
        print('0')
    else:
        print(counter)

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
    b_c = 0
    b_b_c = 0
    for i in range(N):
        if S[i] == w and S[i-1] == b:
            if b_b_c == 0:
                #b_c = 0
                w_c = 0
                for j in range(i, N+1):
                    if S[j] == w:
                        w_c += 1
                    else:
                        break
                #for k in range(0, i)[::-1]:
                #    if S[k] == b:
                #         b_c += 1
                #    else:
                #        break

                #print(w_c)
                #print(b_c)
                if w_c > b_c:
                    for h in range(0, i)[::-1]:
                        if S[h] == b:
                            S[h] = w
                            c += 1
                        else:
                            break
        if S[i] == b:
            b_c += 1
        else:
            if b_b_c == 0:
                b_b_c = b_c
            b_c = 0
        if S[i] == b:
            if S[i-1] == w and S[i+1] == w:
                S[i] = w
                c += 1
                continue
        if i > 0 and S[i] == w:
            #print(S)
            #print(S[i])
            if S[i-1] == b:
                S[i] = b
                c += 1
    i = N
    if i == N:
        #print("a")
        #print(S)
        #print(S[i])
        if S[i-1] == b and S[i] == w:
            S[i] = b
            c += 1
    return c


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if b < a:
        a,b = b,a
    if a <= c <= b:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    s = input()
    a = list(set(list(s)))
    k = II()-1
    for i in a:
        if s[k] != i:
            s = s.replace(i, "*")
    print(s)
    return

#C
def C():
    n = II()
    s = S()
    a, b = 0, 0
    for i in s:
        if i == "#":
            a += 1
        else:
            b += 1
    x,y = 0,0
    for i in s:
        if i == ".":
            x += 1
            continue
        break
    for i in s[::-1]:
        if i == "#":
            y += 1
            continue
        break
    print(min(a - y, b - x))
        


    """
    dp = []
    bf = s[0]
    del s[0]
    a = 
    flg = False
    if bf == ".":
        flg = True
    for i in s:
        if i == bf:
            a += 1
        else:
            dp.append(a)
            a = 1
            bf = i
    dp.append(a)
    a, b = 0, 0
    if flg:
        dp[0] = 0
    if len(s) and s[-1] == "#":
        dp[-1] = 0
    for d in range(len(dp) - 2, -1, -2):
        a += dp[d]
    for d in range(len(dp) - 1, -1, -2):
        b += dp[d]
    print(dp)
    print(min(a,b))
    """
    return

#D
def D():
    n = II()
    ai = IR(n)
    ai.sort()
    ruiseki = [0 for i in range(n)]
    for num, a in enumerate(ai):
        ruiseki[num] = a + ruiseki[num-1]
    select = list(itertools.combinations(range(n), 3))
    ans = 0
    for a,b,c in select:
        A = ruiseki[a]
        B = ruiseki[b] - ruiseki[a]
        C = ruiseki[c] - ruiseki[b]
        if A + B > C and B + C > A and A + C > B:
            ans += 6
            ans = ans % mod
    print(ans)
    
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(set(S)) == 1:
    print(0)
    quit()

a = S.count(".")
b = S.count("#")
ans2 = min(a,b)

ans = 0

if S[0] == "#":
    i = 1
    while True:
        if S[i] == ".":
            ans = i
            S = S[i:]
            break
        else:
            i += 1
else:
    flag = False
    for i in S:
        if i == "#":
            flag = True
        if flag and i == ".":
            break
    else:
        print(0)
        quit()

if len(set(S)) == 1:
    print(ans2)
    quit()

if S[-1] == ".":
    i = 2
    while True:
        if S[-i] == "#":
            ans += (i-1)
            S = S[:-i+1]
            break
        else:
            i += 1


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

print(min(min(S.count("."), S.count("#")) + ans, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
stone_list = list(input())
stone_list.append('end')
if stone_list[0] == '#':
    stone_list.insert(0,'.')

normalized_list = []
count = 0
stone = stone_list[0]
for s in stone_list:
    if s == stone:
        count += 1
    else:
        normalized_list.append(count)
        count = 1
        stone = s
    

total_a = 0
for i in range(1,len(normalized_list)-1,2):
    total_a += normalized_list[i]
    
total_b = 0
for i in range(2,len(normalized_list),2):
    total_b += normalized_list[i]

print(min(total_a,total_b))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
 
res = 0
for i in range(len(S)-1):
    if S[i] == '#' and S[i+1] == '.':
        if i+2 <= len(S)-1:
            if i > 0:
                if S[i-1] != '#':
                    S[i] = '.'
                    res += 1
                    continue
            else:
                S[i] = '.'
                res += 1
                continue

        res += 1
        S[i+1] = '#'

print(res)

Submission status: Wrong Answer

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

1 <= N <= 2*10^5

if S.count("#") > S.count("."):
  print(S.count("."))
elif S.count(".") > S.count("#"):
  print(S.count("#"))
elif S.count("#") == N or S.count(".") == N:
  print(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = list('##.#')
b = list('##..')
c = list('.#.#')
d = list('.#..')
ans = 0
if N == 1:
    print(0)
elif N == 2:
    if S == '#.':
        print(1)
    else:
        print(0)
elif N == 3:
    if S.find('#.') != -1:
        print(1)
    else:
        print(0)
else:
    S = '.' + S
    S = S + '#'
    LS = list(S)
    t = list(S[:4])
    e = 3
    N += 2
    while True:
        if t == a:
            ans += 1
            #LS[e-1]  = '#'
            t[2] = '#'
        elif t == b:
            ans += 1
            t[2] = '#'
            #LS[e-1]  = '#'
        elif t == c:
            ans += 1
            t[2] = '#'
            #LS[e-1] = '#'
        elif t == d:
            ans += 1
            t[1] = '.'
            #LS[e-2] = '.'
        e += 1
        if e > N-1:
            break
        t = t[1:] + [LS[e]]
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
 
s = list(s)
 
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:
# -*- coding: utf-8 -*-
n = int(input())
s = str(input())
s = s.replace(".", "0").replace('#', "1")
b = s.find("1")
a = 0
for i in range(b, n):
    a+=int(s[i])
s = [int(n) for n in s]
sums = sum(list(s))
if sums==0:
    print(0)
else:
    if n-b-a>sums:
        print(sums)
    else:
        print(n-b-a)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
for x in range(N):
    if x == 0:
        ans = S.count(".")
    continue
    count = S[:x].count("#") + S[x+1:].count(".")
    if count < ans:
        ans = count
count = S.count("#")
if count < ans:
    ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=10**9+7
for i in range(N-1):
    ans=min(S[:i].count(".")+S[i:].count("#"),ans)
print(ans)

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:
N = int(input())
S = list(input())

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

# cnt = 0
# target = S[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
# aim = S[-1]
# for i in range(N-1, -1, -1):
#     if aim == '.' and S[i] == '#':
#         cnt_2 += 1
#         aim = '.'
#         continue
#
#     if S[i] == '#':
#         aim = '#'
#     else:
#         aim = '.'
#
#
# print(int(min(cnt, cnt_2)))

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

less_color = min(black, white)
if (black <= white) or S[-1] == '#':
    less_color -= 1

print(less_color)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

while(i<n and s[i] == "."):
	i+=1
print(i)
while(i<l and s[l] == "#"):
	l-=1
print(l)

for j in range(i,l+1):
	cnt[s[j] == "."] += 1
	
print(cnt)
print(min(cnt))

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = list(input())
 
S_1 = copy.copy(S)
S_2 = copy.copy(S)
S_3 = copy.copy(S)
S_4 = copy.copy(S)
count_1 = 0
count_3 = 0

for i in range(N-1):
  if S_1[i] == "#" and S_1[i+1] == ".":
    if i != N - 2:
      if S_1[i+2] == "#":
        S_1[i+1] = "#"
      else:
        S_1[i+1] = "."
    count_1 += 1
    
#for i in range(N-1):
#  if S_2[i] == "#" and S_2[i+1] == ".":
#    S_2[i] = "."
#    count_2 += 1
    
for i in range(N-1):
  if S_3[N - i - 1] == "." and S_3[N - i - 2] == "#":
    if i != N - 2:
      if S_3[N - i -3] == "#":
        S_3[N - i - 1] = "#"
      else:
        S_3[N - i - 2] = "."
    count_3 += 1
    
#for i in range(N-1):
#  if S_4[N - i - 1] == "." and S_4[N - i - 2] == "#":
#    S_4[N - i - 2] = "."
#    count_4 += 1
    
print(min(count_1, count_3))

Submission status: Wrong Answer

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

for i in range(n-1):  
  if s[i] == "#" and s[i+1]==".":
      s=s.replace(s[i+1],"#")
      
      N+=1
print(N)

Submission status: Wrong Answer

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

# if (S not in "#"):
#     print("0")
#     exit()
count = 0
ans = 0
revcount = 0
Flag = False
for i in range(N-1,-1,-1):
    #print(S[i])
    if S[i] == ".":
        Flag = True
        count+=1
    else:
        if Flag == True:
            revcount+=1
            Flag = False
        ans+=count
        count=0
#print(revcount,ans)
print(min(revcount,ans))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
ans=0
if s.count(".")==n or s.count("#")==n:
    print(0)
    sys.exit()
for i in range(len(s)):
    if s[i]=="#":
        ans=s[i+1:].count(".")
        ans1=s[i:].count("#")
        break
if s[-1]=="#":
    s="".join(reversed(s))
    tmp=s.find(".")
    print(min(ans,ans1-tmp))
else:
    print(min(ans,ans1))

Submission status: Wrong Answer

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


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

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


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

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
if N == 1:
    print(0)
    exit()
elif N == 2 and (S[0] == '#' and S[1] == '.'):
    print(1)
    exit()
else:
    S = '#' + S + '#'
    for n in range(N):
        if S[n] == '.' and S[n + 2] == '.' and S[n + 1] == '#':
            ans += 1
        elif S[n] == '#' and S[n + 2] == '#' and S[n + 1] == '.':
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
_ = input()
s = list(input())
cnt = 0

for i in range(len(s)-1):
    if s[i] != s[i+1] and s[i+1]=='.':
        cnt += 1
        try:
            if s[i+2] == '.':
                s[i] = '.'
            else:
                s[i+1] = '#'
        except:
            s[i+1] = '#'

print(cnt)

Submission status: Wrong Answer

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


ini_w = 0
for i in range(len(S)):
    if S[i] == '.':
        ini_w = ini_w + 1
    else:
        break
    
if ini_w >= len(S)-1:
    print(0)
    exit()
    
S = S[ini_w:]

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

other = 2*10000000

last_b = 0

for i in range(len(S)):
    if S[len(S)-i-1] == '#':
        last_b = last_b + 1
    else:
        break

other = all_w - last_b
print(min(all_w,all_b,other))

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
scount=0
ccount=0
pp=0
ll=list()
for i in b:
        ll.append(i)
if "#" in ll:
        x=ll.index("#")
        y=ll.count(".")
        z=y-x
        q=ll.count("#")
        ccount=z
        
        for i in range(int(a)):
                scount-=1
                if ll[scount] == ".":
                        break
                else:
                        pp+=1
        if q-pp<z:
                ccount=q-pp

                
        
print(ccount)

Submission status: Wrong Answer

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

def count_diff(str1, str2):
  return sum([1 if j == str2[i] else 0 for i, j in enumerate(str1)])

if '.' not in s or '#' not in s:
  print(0)
elif '#.' not in s:
  print(0)
else:
  if s[n-1] == '#':
    s = s[:s.rfind('.')+1]
  if '#' in s:
    s = s[s.find('#'):]
  len_s = len(s)
  q = ['.' * i + '#' * (len_s - i) for i in range(0, len_s+1)]
  print(min([count_diff(s, te) for te in q]))

Submission status: Wrong Answer

Solution code:
inp_num=int(input())
inp=input()
w1=0
b1=0

bf=0
wf=0

for i in range(len(inp)):
    if inp[i]=='#' and wf==0:
        wf=1
        b1=b1+1
    elif inp[i]=='#' and wf==1:
        b1=b1+1
    elif inp[i]=='.' and wf==1:
        w1=w1+1

w2=0
b2=0

for i in range(len(inp)):
    if inp[len(inp)-i-1]=='.' and bf==0:
        bf=1
        w2=w2+1
    elif inp[len(inp)-i-1]=='#' and bf==1:
        b2=b2+1
    elif inp[len(inp)-i-1]=='.' and bf==1:
        w2=w2+1

line=[b1,w1,b2,w2]
#print(line)
print(min(line))

Submission status: Wrong Answer

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

kurodeta = False
cnt = 0
for stone in S:
    if not kurodeta and stone == ".":
        continue

    if stone == "#":
        kurodeta = True

    if stone == ".":
        cnt += 1


shirodeta = False
kurocount = 0
for stone in reversed(S):
    if not shirodeta and stone == "#":
        continue

    if stone == ".":
        shirodeta = True

    if stone == "#":
        kurocount += 1

print(min(cnt, kurocount))

Submission status: Wrong Answer

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

flag = -1
for char in S:
    if (char == '#' and flag == -1) or (flag != -1 and char == '.'):
        flag += 1
if flag == -1:
    flag += 1
print(flag)

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] == "#" and s_list[nump] == ".":
    s_list[nump] = "#"
    changednum += 1
  else:
    pass
#sed = "".join(s_list)
print(changednum)