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

kind = []
stone = []
change = []
s = 0

for i in range(N):
    if i == 0:
        kind.append(S[i])
        s += 1
    elif S[i-1] != S[i]:
        stone.append(s)
        kind.append(S[i])
        s = 1
    else:
        s += 1
    if i == N-1:
        stone.append(s)

if len(kind)==1:
    print(0)
else: 
    min = 0
    # print(kind, stone)
    if kind[0] == '.':
        start = 1
    else:
        start = 0 
    # .の数を数えて足す
    for i in range(start+1,len(stone),2):
        min += stone[i]
        # print('i=', i, 'min=', min)
    # #の個数を持つstoneのindexがi
    for i in range(start,len(stone),2):
        if i==start:
            tmp = min
        else:
            tmp += stone[i-2]
            tmp -= stone[i-1]
        if tmp < min:
            min = tmp
    print(min)

Submission status: Wrong Answer

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

print('find:', S.find('#', 1))
for i in range(len(S)):
    if S.find('#', i) == -1:
        break
    # 連続した'#'から'.'に変わった場合,'.'の出現をカウントする
    if S.find('#', i) != i:
        count += 1

print(count)

Submission status: Wrong Answer

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

s = S

ans = 2 * 10 ** 5
for i in range(N):
    #print(S[:i], '     ',S[i:])
    sharp_num = s[i:].count('#') # 後ろを#→.
    dot_num = s[:i].count('.') # 前を . → #
    ans = min(ans, dot_num + sharp_num)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c = 0
A = int(S.count("."))
B = N - A
if len(S) == N:
    if 1 <= N <= 2 * 10 ** 5:
        if "." in S:
            if "#" in S:
                S.replace("#.","ee")
                D = S.find("e") + 1
                C = N - D + 1                
                print(N - C + B)
            else:
                print(0)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
A=[]
B=[]
for i in S:
    A.append(i)
for i in S:
    B.append(i)
count1=0
count2=0
for i in range(N-1):
    if (A[i]=="#")and( A[i+1]=="."):
        A[i+1]="#"
        count1+=1


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

ans=min(count1,count2)
print(ans)

Submission status: Wrong Answer

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

flag = False

for x in range(N)[::-1]:
    if S[x] == '.':
        flag = True
    if S[x] == '#' and flag == True:
        count2 += 1

print(min(count,count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
whites = S.count('.')
stones = [0, whites]
ans = 1000000
for char in S:
    if ans > sum(stones):
        ans = sum(stones)
    if char == '.':
        stones[1] -= 1
    else:
        stones[0] += 1
print(ans)

Submission status: Wrong Answer

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

sl = list(s)


def count_black(wb):
    return wb.count('#')


def count_white(wb):
    return wb.count('.')


min_count = n
for i in range(1, n):
    if sl[i-1] != sl[i]:
        count = count_black(sl[:i-1]) + count_white(sl[i:])
        if min_count > count:
            min_count = count

print(min_count)

Submission status: Wrong Answer

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

a = S.count('.')
r = a

for i in range(N):
    if S[0] == '#':
        a += 1
    else:
        r -= 1

print(min(a,r + a))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
count = 0
lst = []
for i,char in enumerate(S):
  if (char == "."):
    lst.append(i)

min = 0   
length = len(lst)
if (length == 0):
  print(min)
elif(length == 1):
  if (lst[0] == 0):
    print(min)
  else:
    min = 1
    print(min)
else:
  for idx, i in enumerate(lst):
    if (idx > 0):
      count += lst[idx] - lst[idx-1] -1 
  if (count > length):
    min = length
  else:
    min = count
  print(min)

Submission status: Wrong Answer

Solution code:
###
#main
if __name__ == "__main__":
    N = int(input())
    S = input()
#    count = 0
    countMin = 200001
    counttemp = 0
    isWhite = True
    numlist = []
    for t in S:
        if t == "#" and isWhite:
            isWhite = False
            numlist.append(counttemp)
            counttemp = 0
        if t == "." and not isWhite:
            isWhite = True
            numlist.append(counttemp)
            counttemp = 0
        counttemp += 1
    
    numlist.append(counttemp)
    if len(numlist) <= 2:
        countMin = 0
    else:
        countMin = sum(numlist[2::2])
        temp = countMin
        i = 2
        while i < len(numlist):
            temp += numlist[i-1] - numlist[i] if numlist[i-1] < numlist[i] else 0
            countMin = temp if temp < countMin else countMin
            i += 2
#    print(numlist)           
    print(countMin)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
r = []

for i in range(N):
  left = S[:N].count("#")
  right = S[N:].count(".")
  r.append(left + right)
  
print(min(r))

Submission status: Wrong Answer

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

sign = True
change1 = len(S)
change2 = len(S)

for i in range(len(S)-1):
	if S[i] !=S[i+1]:
		if sign:
			change1 = i+1
			sign = False
		else:
			change2 = i+1
			break
if S[0] == '.':
	print(min(S.count('.'),S[change1:].count('.'),S.count('#')))
else:
	print(min(S.count('.'),S[change2:].count('.')+change1,S.count('#')))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        #break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        #break

count=0
#print(dot)#左から
#print(sha)#右から
count_a=0
count_b=0
#d=10**
for i in range(N):
    if i<dot and S[i]!=".":
        count_a+=1
for i in range(N):
    if i<sha and s_r[i]!="#":
        count_b+=1
#print(count)
if dot-1<=sha:
    c=count_a+count_b
else:
    c=min(count_a,count_b)

a=0
b=0

for i in range(N):
    if S[i]!=".":
        a+=1
    if S[i]!="#":
        b+=1

#print(count)
ans=min(a,b,c)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = 200000
w = [0 for i in range(n+1)]
for i in range(n):
    if s[i] == '.':
        w[i] = w[i - 1] + 1
    else:
        w[i] = w[i - 1]
w[n] = w[n - 1]
for i in range(n):
    x = (i+1 - w[i]) + (w[n - 1] - w[i])
    ans = min(x, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
S = [0 if si == "#" else 1 for si in S]
def taskC(N,S):
    Wlist = []
    Blist = []
    Wcount = 0
    Bcount = 0
    S0 = S[0]
    for si in S:
        if si == 0:
            Bcount += 1
            if Wcount > 0:
                Wlist = [Wcount] + Wlist
                Wcount = 0
        else:
            Wcount += 1
            if Bcount >0:
                Blist += [Bcount]
                Bcount = 0
    Wlist = ([Wcount] + Wlist) if Wcount > 0 else Wlist
    Blist = (Blist + [Bcount]) if Bcount > 0 else Blist
    if len(Wlist)+len(Blist) <= 1:
        return 0
    if len(Wlist)>len(Blist):
        Wlist = Wlist[:-1]
        S0 = 0
    elif len(Blist)>len(Wlist):
        Blist = Blist[:-1]
        S0 = 0
    Wsum = [0]
    Bsum = [0]
    for ind in range(len(Wlist)):
        Wsum = [ Wsum[0] + Wlist[ind]] + Wsum
        Bsum += [ Bsum[-1] + Blist[ind]]
    ret = min([Wsum[i]+Bsum[i] for i in range(len(Wsum))])
    if S0 == 0:
        ret2 = min([Wsum[i]+Bsum[i+1] for i in range(len(Wsum)-1)])
        return min(ret, ret2)
    else:
        ret2 = min([Wsum[i+1]+Bsum[i] for i in range(len(Wsum)-1)])
        return min(ret, ret2)
taskC(N,S)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        #break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        #break

count=0
#print(dot)#左から
#print(sha)#右から
count_a=0
count_b=0
#d=10**
for i in range(N):
    if i<dot and S[i]!=".":
        count_a+=1
for i in range(N):
    if i<sha and s_r[i]!="#":
        count_b+=1
#print(count)
if dot<=sha-1:
    c=count_a+count_b
else:
    c=min(count_a,count_b)

a=0
b=0

for i in range(N):
    if S[i]!=".":
        a+=1
    if S[i]!="#":
        b+=1

#print(count)
ans=min(a,b,c)
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = str(input())
res = 0
 
for i in range(a):
    if b[i:i+2] == "#.":
        res = b[i:].count(".")
        break

print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
m=S[::-1]
c=S.count('#')
if ('.' in S) & ('#' in S):
	p=S.index('#')
	l=m.index('.')
	k=S[p::]
	a=k.count('.')
	if (p!=0)&(a==0):
		print(0)
	elif a>=c:
		 print(c-l)
	else:
		 print(a)
else:
	print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = []
judge = False
for i in range(N):
  cnt.append(S[0:i].count("#")+S[i:N].count("."))
print(min(cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
count = 0
lst = []
for i,char in enumerate(S):
  if (char == "."):
    lst.append(i)

min = 0   
length = len(lst)
if (length == 0):
  print(min)
elif(length == 1):
  if (lst[0] == 0):
    print(min)
  else:
    print("1")
else:
  for idx, i in enumerate(lst):
    if (idx > 0):
      count += lst[idx] - lst[idx-1] -1 
  if (count > length):
    min = length
  else:
    min = count
  print(min)

Submission status: Wrong Answer

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

sign = True
change1 = len(S)
change2 = len(S)

for i in range(len(S)-1):
	if S[i] !=S[i+1]:
		if sign:
			change1 = i+1
			sign = False
		else:
			change2 = i+1
			break
if S[0] == '.':
	print(min(S.count('.'),S[change1:].count('.')))
else:
	print(min(S.count('.'),S[change2:].count('.')+change1))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1

print(min(ans,num))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
white = '.'
black = '#'

cnt = 0
for i in S:
    if(i==black):
        break
    else:
        cnt += 1
#print(cnt)
#print(S)
bS = S[cnt:]
#print(S)

black_chg_cnt = 0
white_chg_cnt = 0
for i in bS:
    if(i==white):
        black_chg_cnt += 1
    else:
        white_chg_cnt += 1

if(S[-1] == black):
    white_chg_cnt -= 1

if(black_chg_cnt<white_chg_cnt):
    print(black_chg_cnt)
else:
    print(white_chg_cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(input())
c = 0
d = 0
e = []
st = a[N-1]
f = [st,1]
for i in range(2,N+2):
    if a[N-i] == st:
        f[1] += 1
    else:
        e.append(f)
        st = a[N-i]
        f = [st,1]
e.append(f)
for i in range(len(e) - 1):
    if e[i][0] == ".":
        c += e[i][1]
if e[len(e)-1][0] ==".":
    d += e[len(e)-1][1]
print(min(c,N-c-d))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
count=0
count1=0
now=0
for i in range(n-1,0,-1):
  if s[i]=="#":
    count=count+1
  else:
    count1=count1+1
  if count<count1:
    now=i-1
    break
for i in range(now,0,-1):
  if s[i]=="#":
    count=count+1
print(count)

Submission status: Wrong Answer

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

w_num = S.count('.')
b_num = S.count('#')

if '#.' in S:
    if w_num > b_num:
        count = S.count('#.')
    elif w_num <= b_num:
        for i in range(N):
            if S_list[i] == '#' and S_list[i+1] == '.':
                count += 1
                S_list[i+1] = '#'
                S = ''.join(S_list)
            if  '#.' in S:
                pass;
            else:
                break;
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s = [S[i: i + 1] for i in range(N)]
ans = 0
bflag = 0
for i, st in enumerate(s):
    if bflag == 1:
        if st == '.':
            ans += 1
    else:
        if st == '#':
            bflag = 1
wflag = 0
ans2 = 0
for i in range(1, N + 1):
    if wflag == 1:
        if s[-i] == '#':
            ans2 += 1
    else:
        if s[-i] == '.':
            wflag = 1
print(min(ans, ans2))

Submission status: Wrong Answer

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

s = S

ans = 2 * 10 ** 5
print(ans)
for i in range(len(s)):
    #print(S[:i], S[i:])
    sharp_num = s[i:].count('.') # 後ろを#→.
    dot_num = s[:i].count('#') # 前を . → #
    ans = min(ans, dot_num + sharp_num)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = s.count('.')
tmp = ans
for i in s:
    if i == '.':
        ans -= 1
    else:
        ans += 1

print(min(ans,tmp))

Submission status: Wrong Answer

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

a = S.count('.')
r = a

for i in range(N):
    if S[0] == '#':
        a += 1
    else:
        r -= 1

print(min(a,r))

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, S):

    ans = 0
    prev = S[0]
    for i in xrange(len(S)-1):
        if prev == "#" and S[i+1] == ".":
            ans += 1
            prev = "#"
        else:
            prev = S[i+1]
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    ans = solve(int(N), S)
    print ans

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = 200000
w = [0 for i in range(n+1)]
for i in range(n):
    if s[i] == '.':
        w[i] = w[i - 1] + 1
    else:
        w[i] = w[i - 1]
for i in range(n):
    x = (i+1 - w[i]) + (w[n - 1] - w[i])
    ans = min(x, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
l = []
c = 0
d = 0
ans = 10**6

if s.count("#")==0:
    print(0)
else:
    for i in range(N):
        if s[i] == "#":
            if d != 0:
                c += 1
                d += 1
            else:
                l.append(c + s[i:N+1].count("."))
                c += 1
                d += 1
        else:
            d = 0
    print(min(l))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().rstrip()
#最後尾の白を見つけその前の黒を白に
answer1 = S[:S.rfind(".")+1].count("#")
#先頭の黒を見つけその後ろの白を黒に
answer2 = S[S.find("#"):].count(".")
answer3 = 10**9
answer4 = 10**9
index = S.rfind(".")
if index == N-1:
    #右黒左白
    S_last = S[S.rfind("#"):index+1]
    S_first = S[:S[:S.rfind("#")].rfind(".")]
    answer3 = S_last.count(".") + S_first.count("#")
index = S.find("#")
if index == 0:
    S_first = S[index:S.find(".")]
    S_last = S[S.find("."):]
    answer4 = S_last.count(".") + S_first.count("#")
    print(answer4)
print(min([answer1, answer2, answer3,answer4]))

Submission status: Wrong Answer

Solution code:
n = int(input())
 
lines = list(input())
 
count_stone = list()
stone = lines[0]
count=0
for i in range(len(lines)):
    if lines[i] == stone:
        count += 1
    else:
        count_stone.append([stone,count])
        stone = lines[i]
        count = 1
    if i == len(lines)-1:
        count_stone.append([stone,count])
    
# print(count_stone)
ans = list()
for i in range(len(count_stone)):
    total = 0
    for j in range(len(count_stone)):
        if j <= i:
            if count_stone[j][0] == '#':
                total += count_stone[j][1]
        else:
            if count_stone[j][0] == '.':
                total += count_stone[j][1]
    ans.append(total)
# print(ans)
print(min(ans))

Submission status: Wrong Answer

Solution code:

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

    right_white = S.count('.')
    left_black = 0

    ans = len(S)
    for i in range(len(S)):
        if S[i] == '#':  # black
            left_black += 1
        else: # white
            right_white -= 1

        ans = min(ans, left_black + right_white)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
m=min(s.count('.'),s.count('#'))
if s[0]=='.' and s[n-1]=='#':
  m=m-2
elif s[0]=='.' or s[n-1]=='#':
  m=m-1
else:
  m=m
print(m)

Submission status: Wrong Answer

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

start = -1
black = 1
white = 0
start2 = -1
black2 = 0
white2 = 1

for i in range(n):
    if s[i] == "#":
        start = i
        break

if start != -1:
    for i in range(n):
        if i > start:
            if s[i] == "#":
                black+=1
            else:
                white+=1

for i in range(n):
    if s[n-i-1] == ".":
        start2 = i
        break

if start != -1:
    for i in range(n):
        if n-i-1 < start2:
            if s[n-i-1] == "#":
                black2+=1
            else:
                white2+=1

if start == -1 or start2 == -1:
    print(0)
else:
    if black < white and black < black2 and black < white2:
        print(black)
    elif white < black and white < black2 and white <white2:
        print(white)
    elif black2 < black and black2 < white and black2 < white2:
        print(black2)
    else:
        print(white2)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w = 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] == '.':
            w += 1
b = N-i-w
print(min(w,b))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
dif = 0
ans_i = 0
mem = -1
for i, char in enumerate(S):
    if char == '.':
        dif += 1
    else:
        dif -= 1
    if abs(dif) > mem:
        mem = abs(dif)
        ans_i = i
print(S[:ans_i+1].count('#') + S[ans_i+1:].count('.'))

Submission status: Wrong Answer

Solution code:
def pro():
    _, s = input(), [s for s in input()]
    if "#" not in s:
        return print(0)
    s = s[s.index("#"):]
    for i in range(len(s)):
        if s[-1] == "#":
            s = s[:-1]
        else:
            break
    a = s.count(".")
    b = len(s) - a
    if a > b:
        return print(b)
    else:
        return print(a)
pro()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
n=len(s)
x = 0
for i in range(n-1):
    if s[i] == "#" and s[i + 1] == ".":
        y1=0
        for j in reversed(range(i + 1)):
            if s[j] == "#":
                y1 += 1
            else:
                break
        y2=0
        for k in range(i+1, n):
            if s[k] == ".":
                y2 += 1
            else:
                break

        x+=min(y1, y2)


print(str(x))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        #break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        #break

count=0
#print(dot)#左から
#print(sha)#右から
count_a=0
count_b=0
#d=10**
for i in range(N):
    if i<dot and S[i]!=".":
        count_a+=1
for i in range(N):
    if i<sha and s_r[i]!="#":
        count_b+=1
#print(count)
if dot<=sha:
    c=count_a+count_b
else:
    c=min(count_a,count_b)

a=0
b=0

for i in range(N):
    if S[i]!=".":
        a+=1
    if S[i]!="#":
        b+=1

#print(count)
ans=min(a,b,c)
print(ans)

Submission status: Wrong Answer

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

count = 0
end = 0
flag = 0

for i in range(len(s)-1):
    if s[i] == '#' and s[i+1] == '.':
        if i == 0 or i == len(s) - 2:
            count += 1
            flag = 1
        elif flag==0:
            if s[:i].count('#') < s[i:].count('.'):
                count += len(s[:i])
            flag = 1
        else:
            if s[i-1] == '.':
                s[i] = '.'
                count += 1
            else:
                s[i+1] = '#'
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li = []
i = 0
j = 0
cnt = 0
ans = 0
while i<n:
    while j<n and s[i]==s[j]:
        cnt += 1
        j += 1
    i = j
    li.append(cnt)
    cnt = 0

if s[0] == "#" and len(li)!=1:
    if len(li)%2==0:
        a = sum(li[0::2])
        b = sum(li[1::2])
        c = li[0] + li[-1]
        ans = min(a, b, c)
    else:
        a = sum(li[0::2]) - li[-1]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
elif s[0] == "." and len(li)!=1:
    if len(li)%2==0:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2]) - li[-1]
        if a<b:
            ans = a
        else:
            ans = b
    else:
        a = sum(li[0::2]) - li[0]
        b = sum(li[1::2])
        if a<b:
            ans = a
        else:
            ans = b
else:
    ans = 0

print(str(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
S = input()
x = []
xp = '#'
c = 0
for n in range(N):
    if S[n] == xp:
        c += 1
    else:
        xp = S[n]
        x.append(c)
        c = 1
x.append(c)
if len(x) % 2 != 0:
    x.append(0)
print(x)
x = np.array(x)
x = np.reshape(x, (-1,2)).T
y = [sum(x[0,:n])+sum(x[1,n:]) for n in range(x.shape[1]+1)]
print(min(y))

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input()) ###
    S = list(input())

    result = 10000
    for i in range(1, len(S)+1):
        left, right = S[:i], S[i:]
        count_sharp = left.count('#')
        count_dot = right.count('.')

        total = count_sharp + count_dot
        # print(left, right, count_sharp,count_dot, total)
        result = min(result, total)
    print(result)

main()

Submission status: Wrong Answer

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

dot = [0] * (N)
sha = [0] * (N)
res = 10**9
for i in range(N):
    tmp = S[:i+1].count(".") + S[i:].count("#")
    if res > tmp:
        res = tmp  

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
count = 0
count_ = 0
if "#" in S:
    for i in range(N):
        if S[i] == "#":
            S_right = S[i:]
            count = S_right.count(".")
            count_ = S_right.count("#")
            break

print(min(count,count_))

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

l = []
now = '.'
count = 0
for i in range(n):
  if ( s[i] != now ):
    l.append(count)
    now = s[i]
    count = 0
  count += 1

if ( count > 0 ):
  l.append(count)

l.append(0)

#print(l)

ans = 99999999999
left = 0
right = 0

for j in range(int((len(l)-1)/2)):
  right += l[(j+1)*2]

for ii in range(int(len(l)/2)):
  i = ii*2

  if( i!=0):
    right -= l[i]

  count = 0
  if ( i!=0):
    left += l[i-1]
  
  count = left + right
  #print(i, count, left, right)
  
  if (ans>count):
    ans = count

if (ans == 99999):
  ans = 0

print(ans)

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:
            print(S)
            #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
            #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_b_c + b_c:
                for h in range(0, i)[::-1]:
                    if S[h] == b:
                        S[h] = w
                        c += 1
            else:
                S[i] = b
                c += 1
                #continue
        if S[i] == b:
            b_c += 1
        else:
            if 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:
input()
S = [1 if v == "." else 0 for v in input()]

count = 0
for s in S:
    if s == 0:
        break
    count += 1

rcount = 0
for s in S[::-1]:
    if s == 1:
        break
    rcount += 1

ones = sum(S) - count
zeros = len(S) - sum(S) - rcount
print(min(ones, zeros))

Submission status: Wrong Answer

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

start = -1
black = 1
white = 0
start2 = -1
black2 = 0
white2 = 1

for i in range(n):
    if s[i] == "#":
        start = i
        break

if start != -1:
    for i in range(n):
        if i > start:
            if s[i] == "#":
                black+=1
            else:
                white+=1

for i in range(n):
    if s[n-i-1] == ".":
        start2 = n-i-1
        break

if start != -1:
    for i in range(n):
        if n-i < start2:
            if s[i] == "#":
                black2+=1
            else:
                white2+=1

if start == -1 or start2 == -1:
    print(0)
else:
    if black < white and black < black2 and black < white2:
        print(black)
    elif white < black and white < black2 and white <white2:
        print(white)
    elif black2 < black and black2 < white and black2 < white2:
        print(black2)
    else:
        print(white2)

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
list_S = list(S)
num = len(list_S)
N = 0
X = list_S.count('.')

if num == X:
    print('0')
else:
    for num in list_S:
        if list_S[N] == '.':
            N += 1
        else:
            list_SS = list_S[N:]
            X1 = list_SS.count('.')
            print(X1)
            break

Submission status: Wrong Answer

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

count = 0
ans = 99999999999
revcount = 0
# for i in range(N-1,-1,-1):
#     if S[i] == ".":
#         count+=1
#         #revcount = 0
#     else:
#         revcount+=1
#         ans+=count
#         count=0
for i in range(N-1,-1,-1):
    p =S[0:i].count("#") +S [i:].count(".")
    ans = min(p,ans)
#print(revcount,ans,N-p)
#print(min(revcount,ans,S[:N-p].count("#")))
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

l = []
now = '.'
count = 0
for i in range(n):
  if ( s[i] != now ):
    l.append(count)
    now = s[i]
    count = 0
  count += 1

if ( count > 0 ):
  l.append(count)

l.append(0)

print(l)

ans = 99999999999
left = 0
right = 0

for j in range(int((len(l)-1)/2)):
  right += l[(j+1)*2]

for ii in range(int(len(l)/2)):
  i = ii*2

  if( i!=0):
    right -= l[i]

  count = 0
  if ( i!=0):
    left += l[i-1]
  
  count = left + right
  print(i, count, left, right)
  


  if (ans>count):
    ans = count

if (ans == 99999):
  ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
fb = -1
for i in range(N):
    if S[i] == '#':
        fb = i
        break

cnt = 0
S = S if fb == -1 else S[fb:]
for s in S:
    if s == '#':
        cnt += 1

if cnt:
    print(min(len(S) - cnt, cnt))
else:
    print(0)

Submission status: Wrong Answer

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

import numpy as np
import scipy as sp

def main():
    while True:
        try:
            il = [input() for i in range(2)]
            N = int(il[0])
            S = il[1]
            hoge = 1
            res = 0
            while hoge!=0:
                res = res + S.count('#.')
                S = S.replace('#.', '##')
                hoge = S.count('#.')
            print(res)
        except:
            break

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
len_s = range(len(s))
count_sharp = s.count("#")
count_dot = s.count(".")
for i in len_s:
    print(i)
    if s[i] == "#":
        s = s[i::]
        break
count_sharp = s.count("#")
count_dot = s.count(".")
print(min(count_dot, count_sharp))

Submission status: Wrong Answer

Solution code:
N=input()
S=raw_input()
u=len(S)
l=0
def check(s):
  a=0
  for i in range(s):
    if S[i]=="#":
        a+=1
  for i in range(s,len(S)):
    if S[i]==".":
      a+=1
  return(a)

w=2*10**5
while True:
    m1=(u-l)/3+l
    m2=(u-l)*2/3+l
    cm1=check(m1)
    cm2=check(m2)
    if cm1 < cm2:
        u=m2
    else:
        l=m1

    if u-l <= 6:
        for i in range(min(7, u-l)):
            w=min(w,check(l+i))
        break

print(w)

Submission status: Wrong Answer

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

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

first = 0
position = 0
secondposition = 0
count2 = 0
for i in reversed(range(n)):
    if(first == 0 and s[i] == '#'):
        first += 1
        position = i+1
    if(first == 1 and s[i] == '.'):
        secondposition = i+1
        break;
if(position == 0):
    ans1 = 0
elif(secondposition == 0):
    ans1 =min(n-position,position)
else:
    for j in range(secondposition-1):
        if(s[j] == '#'):
            count2 += 1

    count1 = n - position

    ans1 = count1 + count2


first2 = 0
position2 = 0
secondposition2 = 0
count4 = 0
num1 = 0
num2 = 0
for i in range(n):
    if(s[i] == '.'):
        num1 += 1
    elif(s[i] == '#'):
        num2 += 1

for i in range(n):
    if(first2 == 0 and s[i] == '.'):
        first2 += 1
        position2 = i+1
    if(first2 == 1 and s[i] == '#'):
        secondposition2 = i+1
        break;
if(position2 == 0):
    ans2 = 0
elif(secondposition2 == 0):
    ans2 = min(n-position2+1,position2)
else:
    for j in range(secondposition2-1,n):
        if(s[j] == '.'):
            count4 += 1

    count3 = position2-1

    ans2 = count3 + count4
print(min(ans1,ans2,num1,num2))