Problem:


Score : 300 points

Problem Statement

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
#.#

Sample Output 1

1

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

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cum_sum = [0 for _ in range(n)]

for i in range(n):
    if s[i] == '#':
        cum_sum[i] += 1

for i in range(n-1):
    cum_sum[i+1] += cum_sum[i]

#print(cum_sum)

ans = 10 ** 10
for i in range(n):
    tmp = 2 * cum_sum[i] + n - i - 1 - cum_sum[n-1]
    #print(ans, tmp)
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
ans = 0

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import Counter

def main():
    N = II()
    S = SI()
    a, b = S.find('#'), S.rfind('.')
    if a == -1 or b == -1:
        return 0
    ans0 = S[a:].count('.')
    ans1 = S[:b].count('#')
    ans = min(ans0, ans1)
    return ans

print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N = int(input())
S = input()
W = [int(s == '.') for s in S]
W = list(accumulate(W))
W += [W[-1]]
w = W[-1]
B = [int(s == '#') for s in S]
B = list(accumulate(B))
print(min(w-i+j for i, j in zip(W, B)))

Submission status: Wrong Answer

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


def main():
    n = int(input())
    s = input()
    lw = 0
    for i in range(len(s)):
        if s[i] == '#':
            break
        lw += 1
    rb = len(s)
    for i in range(len(s)):
        if s[len(s)-i-1] == '.':
            break
        rb -= 1
    w = sum(1 for c in s[lw:rb] if c == '.')
    print(min(w, len(s[lw:rb])-w))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import queue


N = int(input())
S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]

ch = False
ans = 0
bl  = 0
for s in S:
	if s == "#":
		ch = True
		bl += 1
	elif ch and s == ".":
		ans += 1
print(min(ans,bl))

Submission status: Wrong Answer

Solution code:
input()
S = input()

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

BK = S.count('#')
print(min(BK, len(S) - BK))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = S()
    c = 0
    for i in range(n):
        if s[i] == '#':
            break
        c = i
    r = 0
    for i in range(c, n):
        if s[i] == '.':
            r += 1
    c = n-1
    for i in range(n-1,-1,-1):
        if s[i] == '.':
            break
        c = i
    t = 0
    for i in range(c,-1,-1):
        if s[i] == '#':
            t += 1

    return min(r,t)


print(main())

Submission status: Wrong Answer

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

B=0
W=0
Flag=0
for i in range(len(S)):
    if S[i]=="#":
        Flag=1
    if Flag==1:
        if S[i]=="#":
            B+=1
        else:
            W+=1
print(min(B,W))

Submission status: Wrong Answer

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

for i in range(N):
	if judge == 0:
		if S[i] == ".":
			continue
		else:
			judge = 1
	else:
		if S[i] == ".":
			ans += 1
judge2 = 0
ans2 = 0
for i in range(N):
	if judge2 == 0:
		if S[N - i - 1] == "#":
			continue
		else:
			judge2 = 1
	else:
		if S[N - i - 1] == "#":
			ans2 += 1
print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
#.はだめ
n = int(input())
s = list(input())

ans = 0
check = False #左に黒がない
counter = 0
for i in range(n):
    if s[i] == "#":
        check = True
    else:
        if check:
            counter += 1
print(counter)

Submission status: Wrong Answer

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

BK = '#'
WT = '.'

c_sum = [0]
t = 0
for ss in s:
    # print(ss)
    if ss == BK:
        t += 1
    c_sum.append(t)

# print(c_sum)

if s.count(BK) == 0:
    print(0)
else:
    cnt = 0
    for i in range(N - 1, -1, -1):
        if (c_sum[i + 1] - c_sum[0]) == 0:
            # 白石だけ
            break
        else:
            if s[i] == WT:
                cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ctb=0;ctw=0;f=0
for i in range(n):
  if s[i]=='.':ctb+=1
  else:ctw+=1
for j in range(n-1):
  if s[j]=='#' and s[j+1]=='.':
    f=+1
if f==0:
  print(0)
else:
  print(min(ctb,ctw))

Submission status: Wrong Answer

Solution code:
n = int(input())
text = input()
if "." not in text:
    print(0)
    exit(0)

pos = text.index(".")
result = 0
for i in range(pos+1, len(text)):
    if text[i] == '#':
        result += 1

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
n = len(s)
white = [0]
for i, si in enumerate(s, 1):
    white.append(white[-1] + (1 if si == '.' else 0))

ans = n
for i in range(n):
    # print(i, (i - white[i]) + (white[n] - white[i]))
    ans = min((i - white[i]) + (white[n] - white[i]), ans)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac
n=int(input())
s=input()
a=[0 if i=="#" else 1 for i in s]
b=sum(a)
p=list(ac(a))
d=float("inf")
for i in range(n):
    d=min(i+1-p[i]+(b-p[i]),d)
print(d)

Submission status: Wrong Answer

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

ans = 0
idx = 1e9

for i, ele in enumerate(s):
  if ele==".":
    pass
  else:
    idx = i
    break

if idx<len(s):
  for ele in s[idx::]:
    if ele==".":
      ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    s=input()
    if '.' not in s or '#' not in s:
        print(0)
        return
    j = s.index('.')
    a = len([i for i in s[j:] if i == '#'])
    b = len([i for i in s[:j+1] if i == '.'])
    print(min([a, b]))

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
t=list(s)
a=b=0
for i in range(1,n):
    if t[i]=='.'and t[i-1]=='#':
        t[i]=='#'
        a+=1
t=list(s)
for i in range(1,n):
    if t[i]=='.'and t[i-1]=='#':
        t[i-1]=='.'
        b+=1
print(min(a,b))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__

    str = lambda x=b"": x if type(x) is bytes else __str__(x).encode()

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines += b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


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

    try:
        x = s.index('#')
    except:
        print(0)
        return

    try:
        y = s.index('.')
    except:
        print(0)
        return

    print(min(s[:y].count('#'), s[x:].count('.')))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cs = [c for c in s]
ans = 0

zero = False
for i in range(0, n):
    if cs[i] == '#':
        break
else:
    zero = True

ans = sum(1 for c in cs[i:] if c=='.') if not zero else 0

print(ans)

Submission status: Wrong Answer

Solution code:

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

wl = []
bl = []

w=0
b=0

for i in S:
    if i==".":
        w+=1;
    wl.append(w)

for i in reversed(S):
    if i=="#":
        b+=1;
    bl.insert(0, b)

ans = N
for i in range(N):
    if wl[i]+bl[i] > ans:
        ans = wl[i]+bl[i]

print(N - ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    count = 0
    f = False
    for i in S:
        if f and i == ".":
            count += 1
        elif i == "#":
            f = True
            
    print(count)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
last = False
for i in s:
    if i == "#":
        last = True
    else:
        if last:
            ans += 1
        else:
            last = False
s = reversed(list(s))
ans_ = 0
last = False
for i in s:
    if i == ".":
        last = True
    else:
        if last:
            ans_ += 1
        else:
            last = False
print(min(ans, ans_))

Submission status: Wrong Answer

Solution code:
I=lambda:map(int,input().split())
n=int(input())
s=input()
r=0
f=False
for i in range(n):
    if ~f and s[i]=='#':
        f=True
    if f and s[i]=='.':
        r+=1
f=False
t=0
for i in range(n):
    if ~f and s[-1-i]=='.':f=True
    if f and s[-1-i]=='#':t+=1
print(min(r,t))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = N
for i in range(N - 1):
    if S[i] == "#" and S[i + 1] == ".":
        ans = min(ans, sum(S[j] == "." for j in range(i + 1, N)))
        break
else:
    ans = 0

for i in reversed(range(N - 1)):
    if S[i] == "#" and S[i + 1] == ".":
        ans = min(ans, sum(S[j] == "#" for j in range(i + 1)))
        break
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

ans = float("inf")

black = s.count("#")
white = s.count(".")
ans = min(black,white)

bunsuirei = s.find("#")

if bunsuirei != -1:
  ans = min(ans,s[bunsuirei:].count("#"))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(input())
check=False
cnt=0
cnt1=0
for i in range(n):
    if l[i]=='#':
        check=True
    if check==True:
        cnt1+=1
        if l[i]=='.':
            cnt+=1
print(min(cnt1-cnt,cnt))

Submission status: Wrong Answer

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

if '#' in s :
    i = s.index('#')
    cnt = s[i:].count('.')
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
s = input().rsplit()[0]
print(s)
kuro = 0
siro = 0
ans = 0
syo = 0
while syo < n and s[syo] == ".":
    syo += 1
for i in range(syo,n):
    if s[i] == "#":
        if siro:
            ans += min(siro,kuro)
            siro = 0
            kuro = 1
        else:
            kuro += 1
    else:
        siro += 1
ans += min(siro,kuro)
print(ans)

Submission status: Wrong Answer

Solution code:
# S = input()
# N = int(input())
# a = list(map(int, input().split()))
# X = [int(input()) for _ in range(N)]

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

ans1 = 0
ans2 = 0
kuro_frag = False

for i in S:
    if i == "#":
        kuro_frag = True
    elif kuro_frag:
        ans1 += 1

for i in range(N-1):
    if S[i] == "#":
        ans2 += 1

print(min(ans1,ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w = '.'
b = '#'
for i in range(N):
    if S[i] == b:
        break

whites = S[i:].count(w)
blacks = S[i:].count(b)

print(min([whites, blacks]))

Submission status: Wrong Answer

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

count = 0
already = False
for i in s:
    if already:
        if i == '.':
            count += 1
    else:
        if i == '#':
            already = True
print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

flag = False
count = 0
for i in s:
    if(flag == True):
        if(i == "."): count += 1
    elif(i == "#"): flag = True

print(count)

Submission status: Wrong Answer

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

ans = 0

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

ans2 = 0

for i in range(N):
    s = S[i]
    if s == ".":
        continue
    else:
        ans2 += 1
print(min(ans2, ans))

Submission status: Wrong Answer

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

ans = 0
black_found = False

for ch in s:
    if ch == "#":
        black_found = True
    if black_found and ch == ".":
        ans += 1

ans2 = 0
white_found = False
for ch in reversed(s):
    if ch == ".":
        white_found = True
    if white_found and ch == "#":
        ans2 += 1

print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = S()
    c = 0
    for i in range(n):
        if s[i] == '#':
            break
        c = i
    r = 0
    for i in range(c+1, n):
        if s[i] == '.':
            r += 1
    c = n-1
    for i in range(n-1,-1,-1):
        if s[i] == '.':
            break
        c = i
    t = 0
    for i in range(c-1,-1,-1):
        if s[i] == '#':
            t += 1

    return min(r,t)


print(main())

Submission status: Wrong Answer

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

flag = False
cnt = 0
for i in S:
  if i == ".":
    if flag:
      cnt += 1
  else:
    flag = True

flag = False
b = 0
for i in S[::-1]:
  if i == "#":
    if flag:
      b += 1
  else:
    flag = True

print(min(cnt, b))

Submission status: Wrong Answer

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

n = N
w = 0
b = 0
for s in S:
    if b == 0:
        if s == '.':
            n = n - 1
        else:
            b = 1
    else:
        if s == '.':
            w = w + 1
        else:
            b = b + 1

print(min(n-w, n-b))

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = int(input())
stones = input()
black, white = 0,0
for c in stones:
    if c == "#":
        black += 1
    else:
        white += 1


for c in stones:
    if c == ".":
        white -= 1
    else:
        break

print(min(black, white))

Submission status: Wrong Answer

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

count = 0
count_black = 0
start = False
for i in S:
    if not start:
        if i == '#':
            start = True
            count_black += 1
    else:
        if i == '.':
            count += 1
        else:
            count_black += 1

print(min(count_black,count))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ss = s[(s.find('#') + 1):]

a = Counter(ss)['.']
c = Counter(s)
print(min(min(c['#'], c['.']), a))

Submission status: Wrong Answer

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

for i,c in enumerate(S):
    if c == "#":
        break
print(min(S[i+1:].count("."),S.count("#")))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

start = False
cnt = 0
for s in S:
    if (not start) and s == "#":
        start = True
    elif start and s == ".":
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def solve(n, s):
    l = 0
    while l < n and s[l] == '.':
        l += 1
    return s[l :].count('.')

n = int(input())
s = input()
print(solve(n, s))

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
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 998244353

#C
def C():
    n = I()
    s = S()
    b = [s[i] for i in range(n)]
    ans = 0
    for i in range(n-1):
        if s[i] == "#" and s[i+1] == ".":
            ans += 1
            s[i+1] = "#"
    m = 0
    for i in range(n-1)[::-1]:
        if b[i] == "#" and b[i+1] == ".":
            m += 1
            b[i] = "."
    print(min(m,ans))
    return

#D
def D():
    n = I()
    a = IR(n)

    return

#E
def E():
    return

#F
def F():
    return


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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = [0] * (n + 1)
b = [0] * (n + 1)
for i in range(n):
    if s[i] == '.':
        w[i + 1] += 1
    else:
        b[i + 1] += 1

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

num = float('inf')
for i in range(1, n + 1):
    num = min(num, b[i] + w[n] - w[i])

print(num)

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] == '.':
        if i > 0 and i < (N-2) and S[i-1] == '#' and S[i+2] == '.':
            cnt += 2
        else:
            cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
ans = 0
for i in range(N):
    if s[i] == "#":
        for j in range(i + 1, N):
            if s[j] == ".":
                ans += 1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

input()
print(input().count('#.'))

Submission status: Wrong Answer

Solution code:
def main(n):
	flg = False
	s = input()
	ans = 0
	for i in range(0,n-1):
		if s[i] == "#" and s[i+1] == ".":
			flg = True
		if flg and s[i] == ".":
			ans += 1
	if flg and s[n-1] == ".":
		ans += 1
	print(ans)
main(int(input()))

Submission status: Wrong Answer

Solution code:

def main():
    buf = input()
    N = int(buf)
    buf = input()
    S = buf
    white_turn = 0
    black_turn = 0
    has_black = False
    for i in S:
        if i == '.':
            if has_black:
                black_turn += 1
        elif i == '#':
            white_turn += 1
            if not has_black:
                has_black = True
    print(min(white_turn, black_turn))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans1 = 0
ans2 = 0

flag1 = False
flag2 = False
for i in range(n):
    if s[i]=='#':
        flag1 = True
    if flag1 and s[i]=='.':
        ans1 += 1
    if s[i]=='.':
        flag2 = True
    if flag2 and s[i]=='#':
        ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
I=lambda:map(int,input().split())
n=int(input())
s=input()
r=0
f=False
for i in range(n):
    if ~f and s[i]=='#':
        f=True
    if f and s[i]=='.':
        r+=1
print(min(r,s.count('#')))

Submission status: Wrong Answer

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

ans = 0
idx = len(s)

for i, ele in enumerate(s):
  if ele==".":
    pass
  else:
    idx = i
    break

for ele in s[idx::]:
  if ele==".":
    ans += 1

print(ans)

Submission status: Wrong Answer

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

white = 0
black = 0

for s in S:
    if s == '.':
        white += 1
    else:
        black += 1

print(min(white, black))

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    s=input()
    if '.' not in s or '#' not in s:
        print(0)
        return
    j = s.index('.')
    print(len([i for i in s[j:] if i == '#']))

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
judge = 0
ans = 0
for i in range(N):
	if judge == 0:
		if S[i] == ".":
			continue
		else:
			judge = 1
	else:
		if S[i] == ".":
			ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
ans = 0

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s = s[::-1]
#print(s)
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 = list(input())

ans = 0
check = False #左にしろがない
for i in range(n):
    if s[i] == "#":
        if check:
            check = False
            ans += 1
        else:
            check = True
if check:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if "#" not in S:
    print(0)
    sys.exit(0)


num = 0
flag = False
for s in S:
    if s == '#':
        flag = True
    if flag and s == ".":
        num += 1

print(num)

Submission status: Wrong Answer

Solution code:
n=input()
s=input()
ans=s.count('.')
print(ans-len(s.split('#')[0]))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(input())
check=False
cnt=0
for i in range(n):
    if l[i]=='#':
        check=True
    if check==True and l[i]=='.':
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def solve(n, s):
    if s.count('.') == n:
        return 0
    else:
        return s.count('.')

n = int(input())
s = input()
print(solve(n, s))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__

    str = lambda x=b"": x if type(x) is bytes else __str__(x).encode()

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines += b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


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

    try:
        x = s.index('#')
    except:
        print(0)
        return

    print(s[x:].count('.'))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = input()
s = list(raw_input().strip())
ans = 0
for i in xrange(n - 1):
    if s[i] == '#' and s[i + 1] == '.':
        ans += 1
        s[i + 1] = '#'

print ans

Submission status: Wrong Answer

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

ans = 0
black_found = False
ans2 = 0
for ch in s:
    if ch == "#":
        black_found = True
        ans2 += 1
    if black_found and ch == ".":
        ans += 1
print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
import sys


fin = sys.stdin.readline
N = int(fin())
S = fin().rstrip("\n")
assert len(S) == N

prev_color = S[0]
min_changes = 0
for color in S[1:]:
    if prev_color == "#" and color == ".":
        min_changes += 1
    prev_color = color
print(min_changes)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
s = ns()

ans = 0
for si, sj in zip(s[:-1], s[1:]):
    if si == '#' and sj == '.':
        ans += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
judge = 0
ans = 0
for i in range(N):
	if judge == 0:
		if S[i] == ".":
			continue
		else:
			judge = 0
	else:
		if S[i] == ".":
			ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
isBlack = False
for S in Ss:
    if S == '#':
        isBlack = True
    else:
        if isBlack:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
I=lambda:map(int,input().split())
n=int(input())
s=input()
r=0
f=False
for i in range(n):
    if ~f and s[i]=='#':
        f=True
    if f and s[i]=='.':
        r+=1
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
S=input()
ans = 0
flag = 0
for s in S:
    if flag == 0 and s == '#':
        flag = 1
    if flag == 1 and s == '.':
        ans += 1

print(ans)