Problem:


Score : 300 points

Problem Statement

Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.

In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is B, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is W, it means that the color of the corresponding stone is white.

Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.

Constraints

1 ≦ |S| ≦ 10^5

Each character in S is B or W.

Input

The input is given from Standard Input in the following format:

S

Output

Print the minimum number of new stones that Jiro needs to place for his purpose.

Sample Input 1

BBBWW

Sample Output 1

1

By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.

In either way, Jiro's purpose can be achieved by placing one stone.

Sample Input 2

WWWWWW

Sample Output 2

0

If all stones are already of the same color, no new stone is necessary.

Sample Input 3

WBWBWBWBWB

Sample Output 3

9



Sample input:
BBBWW


Sample output:
1

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
cnt = 0
for i in range(1, l):
    if s[i] != s[i - 1]:
        cnt += 1
if cnt == 0 and s[0] == "B":
    cnt = 2
print(cnt)

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
D = [0,0] #B,W
ans = 0; prev = S[0]
for i in range(N):
  if S[i] == "B":
    D[0] += 1
  else:
    D[1] += 1
  if i >= 1:
    if S[i] == prev:
      continue
    else:
      ans += 1
      prev = S[i]
if D[0] == 0: #すべてW
  print(0); exit()
elif D[1] == 0:
  print(2); exit()
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
tmp = S[0]
N = len(S)
for i in range(1, N):
    if i == N-1:
        ans += 1
    if S[i] != tmp:
        tmp = S[i]
        ans += 1
print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
S = input()
print(S)
S = S.replace('\n' , '')
tmp = ""
division_count = 0
for s in S:
    if tmp == "":
        tmp = s
        continue
    if tmp == s:
        continue
    else:
        tmp = s
        division_count += 1
print(division_count)

Submission status: Wrong Answer

Solution code:
s = str(input())
count = 0

for i in range(len(s)):
    for n in range(len(s) - i):
        if s[i] != s[i + n]:
            count += 1
            break
print(count)

Submission status: Wrong Answer

Solution code:
from sys import exit
S = input()
c = S.count("W")
n = len(S)
if c == n or c == 0:
    print(0)
    exit()
cntb = 1000000 if S[0] == "B" and S[-1] == "B"  else 0
cntw = 1000000 if S[0] == "W" and S[-1] == "W" else 0
for s in S.split("B"):
  if s != "":
    cntb += 1
for s in S.split("W"):
  if s != "":
    cntw += 1
print(min(cntb, cntw))

Submission status: Wrong Answer

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

# from numba import njit

# input = stdin.readline

def calcDivision(s):
  res = 0
  prev = ""
  for i in range(len(s)):
    if s[i] == prev:
      pass
    else:
      if s[i] == "":
        pass
      else:
        res += 1
    prev = s[i]
  return res

# @njit
def solve(s):
  return calcDivision(s)



def main():
  s = input()
  print(solve(s))
  return

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#import
#import math
#import numpy as np
#= int(input())
S = input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
#= [list(map(int, input().split())) for _ in range(N)]
#= {i:[] for i in range(N)}

s = S[0]

r = 0

for i in range(1, len(S)):
    if s != S[i]:
        r += 1

    s = S[i]

if S[0] == "B" and S[-1] == "B":
    r -= 1

print(r)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    slen = len(s)
    cnt = 0
    if s[0] == "W":
        for i in range(slen-1):
            if s[i] == "W" and s[i+1] =="B":
                cnt += 1
    if s[0] == "B":
        for i in range(slen-1):
            if s[i] == "B" and s[i+1] =="W":
                cnt += 1
    if cnt == 0:
        print(cnt)
    else:
        print(cnt*2 - 1)
    

 
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
ans,i=-1,0
while i<len(s)-1:
    while i<len(s)-1 and s[i]==s[i+1]:
        i+=1
    i+=1
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
ans,i=-1,0
while i<len(s)-1:
    while i<len(s)-1 and s[i]==s[i+1]:
        i+=1
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
if 'W' not in S:
    print(0)
elif 'B' not in S:
    print(0)
else:
    if S[0] == 'B':
        count = S.count('BW')
        if count == 1:
            print(1)
        else:
            if S[-1] == 'B':
                print(count*2)
            else:
                print(count*2 - 1)
    else:
        count = S.count('WB')
        if count == 1:
            print(1)
        else:
            if S[-1] == 'W':
                print(count*2)
            else:
                print(count*2 - 1)

Submission status: Wrong Answer

Solution code:
S = input()
if 'W' not in S:
    print(0)
elif 'B' not in S:
    print(0)
else:
    if S[0] == 'B':
        count = S.count('BW')
        if count == 1:
            print(1)
        else:
            print(count*2 - 1)
    else:
        count = S.count('WB')
        if count == 1:
            print(1)
        else:
            print(count*2 - 1)

Submission status: Wrong Answer

Solution code:
a = input()
flag = 1
count = 0


while flag == 1:
  p = a.find("WB")
  q = a.find("BW")
  if p != -1 and q != -1 and p < q:
    a = a.replace("W","B",p + 1)
    count += 1
  elif p != -1 and q == -1:
    a = a.replace("W","B",p + 1)
    count += 1
  elif p != -1 and q != -1 and p > q:
    a = a.replace("B","W",q + 1)
    count += 1
  elif p == -1 and q == -1:
    a = a.replace("B","W",q + 1)
    count += 1

  if "BW" not in a and "WB" not in a:
    flag = 0

print(count)

Submission status: Wrong Answer

Solution code:
a = input()
flag = 1
count = 0

while flag == 1:
  p = a.find("WB")
  q = a.find("BW")
  if p != -1 and q != -1 and p < q:
    a = a.replace("W","B",p + 1)
    count += 1
  elif p != -1 and q == -1:
    a = a.replace("W","B",p + 1)
    count += 1
  elif p != -1 and q != -1 and p > q:
    a = a.replace("B","W",q + 1)
    count += 1
  elif p == -1 and q == -1:
    a = a.replace("B","W",q + 1)
    count += 1

  if "BW" not in a and "WB" not in a:
    flag = 0

print(count)

Submission status: Wrong Answer

Solution code:
a = input()
b = a[::-1]
flag = 1
count = 0
count_ = 0

while flag == 1:
  p = a.find("WB")
  q = a.find("BW")
  if p != -1 and q != -1 and p < q:
    a = a.replace("W","B",p + 1)
    count += 1
  elif p != -1 and q == -1:
    a = a.replace("W","B",p + 1)
    count += 1
  elif p != -1 and q != -1 and p > q:
    a = a.replace("B","W",q + 1)
    count += 1
  elif p == -1 and q == -1:
    a = a.replace("B","W",q + 1)
    count += 1

  if "BW" not in a and "WB" not in a:
    flag = 0

flag = 1

while flag == 1:
  p = b.find("WB")
  q = b.find("BW")
  if p != -1 and q != -1 and p < q:
    b = b.replace("W","B",p + 1)
    count_ += 1
  elif p != -1 and q == -1:
    b = b.replace("W","B",p + 1)
    count_ += 1
  elif p != -1 and q != -1 and p > q:
    b = b.replace("B","W",q + 1)
    count_ += 1
  elif p == -1 and q == -1:
    b = b.replace("B","W",q + 1)
    count_ += 1

  if "BW" not in a and "WB" not in b:
    flag = 0

print(min(count,count_))

Submission status: Wrong Answer

Solution code:
import sys

s = input()

before = s[0]
ans = 0
for cx in range(1, len(s)):
    if before != s[cx]:
        ans += 1
        before = s[cx]

print(abs)

Submission status: Wrong Answer

Solution code:
def solve():
    S = input()
    
    if len(set(S)) == 1:
        return 0
    
    d = {'B': 0, 'W': 0}
    ps = S[0]
    d[ps] += 1
    for si in S:
        if si != ps:
            d[si] += 1
        ps = si
    
    ans = sum(d.values())
    if S[0] != S[-1]:
        ans -= 1
    return ans  

print(solve())

Submission status: Wrong Answer

Solution code:
from itertools import groupby
for g, n in groupby(input()):
  print(g, n)

Submission status: Wrong Answer

Solution code:
s = list(input())
compress = [s[0]]

for c in s:
    if c == compress[-1]:
        continue
    compress.append(c)

ans = 0

if compress[0] == 'B':
    ans += 1
if compress[-1] == 'B':
    ans += 1
for c in compress[1:-1]:
    if c == 'B':
        ans += 2
print(ans)

Submission status: Wrong Answer

Solution code:
import re
string = input()
black = white = 0
for i in range(len(string)-2):
    if string[i:i+3] == 'BWB':
        black += 2
    elif string[i:i+3] == 'WBW':
        white += 2
black += (string[0]+string[-1]).count('W')
white += (string[0]+string[-1]).count('B')

print(min(black, white))

Submission status: Wrong Answer

Solution code:
import re
string = input()
match = len(re.findall('BW|WB', string))
if match == 0:
    print(0)
else:
    print(match*2 - 1)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
for i in range(1,len(S)):
  if S[i-1] != S[i]:
    ans += 1

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7


s = list(input())
flag = False
ans = 0
for i in range(len(s)):
    if s[i]== "W":
        break
    else:
        s[i] = "W"
        flag = True
if flag == True:
    ans += 1
flag = False
for i in range(len(s)):
    if s[len(s)-i-1] == "W":
        break
    else:
        s[len(s)-i-1] = "W"
        flag = True
if flag == True:
    ans += 1
c = collections.Counter(s)
for key,value in c.items():
    if key == "B":
        ans += value*2
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
	s = input()
	b = s.count('B')
	w = s.count('W')
	if b != w:
		print(0 if b == 0 or w == 0 else 1)
	else:
		print(len(s)-1)
resolve()

Submission status: Wrong Answer

Solution code:
s=input()
c1=s[0]
if len(s)==1:
    print(0)
res=0
for c in s:
    if c==c1:
        continue
    else:
        res+=1
        c1=c
print(res)

Submission status: Wrong Answer

Solution code:
s=input()
from itertools import groupby as gb
print(len(list(gb(s))))

Submission status: Wrong Answer

Solution code:
s = input()

while s!="":
    if s[-5:]=="dream" or s[-5:]=="erase":
        s = s[:-5]
    elif s[-6:]=="eraser":
        s = s[:-6]
    elif s[-7:]=="dreamer":
        s = s[:-7]
    else:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

Solution code:
s = input()
t = s[0]
res = 0
if len(s)==1:
    print(0)

for i in s[1:]:
    if t == i:
        pass
    else:
       res = res+1
       t = i

print(res)

Submission status: Wrong Answer

Solution code:
s = input()
if len(set(s)) == 1:
  print(0)
else:
  lst = [elem for elem in s.split('W') if elem != '']
  lst2 = [elem for elem in s.split('B') if elem != '']
  print(min(len(lst) * 2 - 1, len(lst2) * 2 - 1))

Submission status: Wrong Answer

Solution code:
s = input()

n = len(s)
ans = 0
tmp = s[0]
lastI = 0

if len(list(set(s))) == 1:
    print(0)
    exit()

for i in range(1, n-1):
    # print(tmp)
    # print(s[i])
    # print(s[i+1])
    # print("----------")
    if s[i] != tmp and s[i+1] == tmp:
        ans += 2
        lastI = i+1

if lastI != n-1:
    ans += 1
# elif lastI == 0:
#     if s[0] != s[1]:
#         ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N =len(S)
cnt = 0

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

Submission status: Wrong Answer

Solution code:
S = input()

if 'B' not in S:
    print(0)
    exit()


S = S.split('B')

count = 0
for i in S:
    if i == '':
        continue
    else:
        count += 1
print(2*count-1)

Submission status: Wrong Answer

Solution code:
S = input().split('B')

if 'B' not in S:
    print(0)
    exit()

count = 0
for i in S:
    if i == '':
        continue
    else:
        count += 1
print(2*count-1)

Submission status: Wrong Answer

Solution code:
s=input()
print(max(s.count('WB'),s.count('BW'))*2-1)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0
check = S[0]

for i in S[1:]:
    if check != S:
        count+=1
        check = i
        
print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())
ans = 0
prestr = s[0]
for id in range(len(s) - 1):
    if prestr == s[id - 1]: continue
    else: 
        ans += 1
        prestr = s[id - 1]
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

print(max(max(s.count("WB"), s.count("BW")) * 2 - 1, 0))

Submission status: Wrong Answer

Solution code:
import re

s = input()

s = re.sub(r"([BW])\1*(?!\1)", r"\1", s)

print(s)

print(int(len(s) - 1))

Submission status: Wrong Answer

Solution code:
import re

Submission status: Wrong Answer

Solution code:
import re
# 盤面の状態
s = input()

# Bにマッチする数を数える
result = re.findall(r'[B]+', s)

#
if s.count("W") == len(s):
    print(0)

elif len(result) %2 ==0:
    print(len(result))
else:
    print(len(result)*2-1)

Submission status: Wrong Answer

Solution code:
import re
# 盤面の状態
s = input()

result = re.findall(r'[B]+', s)
result

if s.count("W") == len(s):
    print(0)

elif len(result) %2 ==0:
    print(len(result))
else:
    print(len(result)*2-1)

Submission status: Wrong Answer

Solution code:
import re
# 盤面の状態
s = input()

cnt = 0

while True:
    # 全部Wになるまで or 1文字残しまで繰り返す
    if s.count("W") == len(s):
        break
    elif len(s)==2:
        cnt +=1
        break

    # 先頭を置換する
    if s[0] == "W":
        s = re.sub(r'[W]+', "", s,1)
        cnt +=1
    elif s[0] == "B":
        s = re.sub(r'[B]+', "", s,1)
        cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


s = list(input())

cnt = 0

for i in range(len(s)):
    if s[i-1] != s[i]:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    if S[0] == "B":
        K = "WB"
    else:
        K = "BW"

    cnt = 0
    for i in range(len(S)-1):
        if S[i:i+2] == K:
            cnt += 1

    if cnt == 0:
        if S[0] == S[-1]:
            ans = 0
        else:
            ans = 1
    else:
        ans = 1 + 2 * cnt

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
s = input()
a = s[0]
for i in range(1,len(s)):
  if s[i]!=s[i-1]: a+= s[i]
if a.count("W") ==0 or a.count("B")==0:
  print(1)
else:
  print(len(a)-1)

Submission status: Wrong Answer

Solution code:
#ABC047 C - 一次元リバーシ / 1D Reversi
S = input()
cur_s = ''
SS=[] 
for i,s in enumerate(S):
    if i==0:
        cur_s = s
        SS.append(cur_s)
        continue
    if i==len(S):
        if cur_s == s:
            continue
        else:
            SS.append(s)
            continue

    if cur_s == s:
        continue
    else:
        SS.append(s)
        cur_s = s

n = len(SS)
m = n//2+1
if n==1:
    print(0)
    exit()

if n%2==1:
    print(m*2)
else:
    print(((n//2)*2)-1)

Submission status: Wrong Answer

Solution code:
def solve():
    s = input()
    # print(s)

    if s.count("W") == 0 or s.count("W") == len(s):
        return 0

    counter = 0
    i = len(s) - 1
    while 0 < i:
        tail = s[i]
        # print("i, tail", i, tail)
        if tail == "W":
            # 右端に B を打つ
            # print("B")
            counter += 1
            # 直近の B を探す
            while 0 < i and not s[i] == "B":
                i -= 1
            # print("\t", i)

            # 左端の B を探す
            if s[i - 1] == "B":
                while 0 < i and s[i] == "B":
                    i -= 1
            # print("\t\t", i)

        else:
            # 右端に W を打つ
            # print("W")
            counter += 1
            # 直近の W を探す
            while 0 < i and not s[i] == "W":
                i -= 1
            # print("\t", i)

            # 左端の W を探す
            if s[i - 1] == "W":
                while 0 < i and s[i] == "W":
                    i -= 1
            # print("\t\t", i)

    # print("c", counter)

    return counter


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Wrong Answer

Solution code:
def solve():
    s = input()
    # print(s)

    if s.count("W") == 0 or s.count("W") == len(s):
        return 0

    counter = 0
    i = len(s) - 1
    while 0 < i:
        tail = s[i]
        # print("i, tail", i, tail)
        if tail == "W":
            # 右端に B を打つ
            # print("B")
            counter += 1
            # 直近の B を探す
            while 0 < i and not s[i] == "B":
                i -= 1
            # print("\t", i)
            assert s[i] == "B"

            # 左端の B を探す
            if s[i - 1] == "B":
                while 0 < i and s[i] == "B":
                    i -= 1
            # print("\t\t", i)

        else:
            # 右端に W を打つ
            # print("W")
            counter += 1
            # 直近の W を探す
            while 0 < i and not s[i] == "W":
                i -= 1
            # print("\t", i)
            assert s[i] == "W"

            # 左端の W を探す
            if s[i - 1] == "W":
                while 0 < i and s[i] == "W":
                    i -= 1
            # print("\t\t", i)

    # print("c", counter)

    return counter


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Wrong Answer

Solution code:
s = input()

count = 0
for i in range(len(s)):
  now = s[i]
  if now != s[i]:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
WB = 'WB'
BW = 'BW'
wcnt = 0
bcnt = 0
for i in range(1, len(S), 2):
    if S[i - 1: i + 1] == WB:
        wcnt += 1
    elif S[i - 1: i + 1] == BW:
        bcnt += 1

ans = 0
wans = 0
if wcnt == 1:
    wans = 1
elif wcnt != 0:
    wans = wcnt * 2 - 1

bans = 0
if bcnt == 1:
    bans += 1
elif bcnt != 0:
    bns = (bcnt * 2 - 1)

if wans != 0 and bans != 0:
    ans = wans * bans
elif wans == 0:
    ans = bans
elif bans == 0:
    ans = wans

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
if len(s) == s.count("B"):
    print(2)
    exit()
ans = 0
if s[0] == "B":
    ans += 1
    while s[0] == "B":
        s = s[1:]

s = s[::-1]

if s[0] == "B":
    ans += 1
    while s[0] == "B":
        s = s[1:]

print(ans+s.count("B")*2)

Submission status: Wrong Answer

Solution code:
s = input()
w = ""
cnt1 = 0
for x in s[1:]:
	if x != w:
		cnt1 += 1
		w = x

print(cnt1)

Submission status: Wrong Answer

Solution code:
s = input()
w = ""
cnt1 = 0
for x in s[1:]:
	if x != w:
		cnt1 += 1

cnt2 = 0
for x in s[-2::-1]:
	if x != w:
		cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
S = list(input())
s = 0
if S[0] == "B":
    for i in range(len(S)-1):
        if S[i] == "B"and S[i+1] == "W":
            s += 1
else:

    for i in range(len(S)-1):
        if S[i] == "W"and S[i+1] == "B":
            s += 1
print(s*2-1)

Submission status: Wrong Answer

Solution code:
S=input()
print(S)
result=0
for i in range(len(S)-1):
  state=S[i]
  if S[i]!=S[i+1]:
    result+=1
  else:
    pass
print(result)

Submission status: Wrong Answer

Solution code:
s=input()
a=s[0]
ans=0
for i in s[1:]:
  if i!=a:
    ans+=1
    a=1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
p = S[0]
ans = 0
for i in range(1, len(S)):
  if S[i] != p: ans += 1
print (ans)

Submission status: Wrong Answer

Solution code:
S=input()
res=0
for i in range(len(S)-1):
  if S[i]!=S[i+1]:
    res+=res
print(res)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
count=0
if n==1:
  print(0)
  exit()
iro=s[0]
for i in range(1,n):
  if s[i]==iro:
    count+=1
  iro=s[i]
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = input()
    
    wko = 0
    bko = 0
    for i in S:
        if i == "W":
            wko += 1
        else:
            bko += 1
    
    ws = S.split("W")
    w_cnt = 0
    bs = S.split("B")
    b_cnt = 0
    
    flg = True
    for i in ws:
        if i != "":
            flg = False
            w_cnt += 1
            
    if flg == True:
        print(0)
        sys.exit()
        
    flg = True
    for i in bs:
        if i != "":
            flg = False
            b_cnt += 1
    
    if flg == True:
        print(0)
        sys.exit()
        
    base = min(w_cnt,b_cnt)
    ans = (base * 2) - 1
    print(ans)
    
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = input()
    ws = S.split("W")
    w_cnt = 0
    bs = S.split("B")
    b_cnt = 0
    
    flg = True
    for i in ws:
        if i != "":
            flg = False
            w_cnt += 1
            
    if flg == True:
        print(0)
        sys.exit()
        
    flg = True
    for i in bs:
        if i != "":
            flg = False
            b_cnt += 1
    
    if flg == True:
        print(0)
        sys.exit()
        
    base = max(w_cnt,b_cnt)
    ans = (base * 2) - 1
    print(ans)
    
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
S = input()
print(max(S.count('WB')*2-1,S.count('BW')*2-1,0))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(S: str):
    def count(s):
        tmp = s[0]
        cnt = 0
        for c in s:
            if c != tmp:
                cnt += 1
                tmp = c
        return cnt
    ret = min(count(S), count(str(reversed(list(S)))))
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s = list(input())
    tmp = s[0]
    res= 0
    if len(s) == 1:
        print(tmp)
    else:
        for i in s[1:]:
            if i != tmp:
                res += 1
                tmp = i
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
newS = ''
if len(S) == 1:print(0)
else:
    i = pre = 0
    while True:
        if i > len(S) - 1:
            newS = newS + S[pre]
            break
        else:
            if S[pre] != S[i]:
                newS = newS + S[pre]
                pre = i
            else:i += 1
print(len(newS)-1)

Submission status: Wrong Answer

Solution code:
s = input()
wb_counter = s.count("WB")
bw_counter = s.count("BW")

max_counter = max(wb_counter, bw_counter)
result = max_counter * 2 - 1
if result == -1:
    print("0")
else:
    print(result)

Submission status: Wrong Answer

Solution code:
b = input()
d = []
isWhite = False
cnt = 0
for i in range(len(b)-1):
  if b[i] != b[i+1]:
    d.append(cnt)
  else:
    cnt+=1

print(len(d)-1)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
temp = S[-1]
for s in S[-2::-1]:
    if s != temp:
        count += 1
    temp = s
print(0 if count == 0 else count-1)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
if S[0] == "W":
    for i in range(0,len(S)-1):
        if S[i] == "W" and S[i+1] == "B":
            count += 1
else:
    for i in range(len(S)-1):
        if S[i] == "B" and S[i+1] == "W":
            count += 1
print(count*2-1 if count > 0 else 0)

Submission status: Wrong Answer

Solution code:
s = input()
while ('WW' in s) or ('BB' in s):
    s = s.replace('WW', 'W').replace('BB', 'B')
num = len(s)-s.count(s[0])
print(2*num-1 if len(s) != 1 else 0)

Submission status: Wrong Answer

Solution code:
n=input()
ans=0
k=(n[0]=="W")
for a in n:
  if k:#w
    if a=="W":
      continue
    else:
      ans+=1
      k=0
  else:#b
    if a=="B":
      continue
    else:
      ans+=1
      k=1
print(ans-1)

Submission status: Wrong Answer

Solution code:
n=input()
ans1=0
k=1
for i in range(len(n)):
  a=n[i]
  if k:#w
    if a=="W":
      continue
    else:
      ans1+=1
      k=0
  else:#b
    if a=="B":
      continue
    else:
      ans1+=1
      k=1
ans2=0
k=1
for i in range(len(n)-1,-1,-1):
  a=n[i]
  if k:#w
    if a=="W":
      continue
    else:
      ans2+=1
      k=0
  else:#b
    if a=="B":
      continue
    else:
      ans2+=1
      k=1
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()
if s.count('B') == 0 or s.count('W') == 0:
    print(0)
    exit()

import re
if s[0] == 'B':
    s = re.sub(r'B+', 'B', s)
    s = re.sub(r'W+', 'W', s)
    print(s.count('BW')*2-1)
else:
    s = re.sub(r'B+', 'B', s)
    s = re.sub(r'W+', 'W', s)
    print(s.count('WB')*2-1)

Submission status: Wrong Answer

Solution code:
S=input()
print(max(0,1+(max(S.count('WB'),S.count('BW'))-1)*2))

Submission status: Wrong Answer

Solution code:
s=list(input())
if ''.join(s)=='WBWBWBWBWB':
  exit()
a=s[0]
s.remove(a)
c=0
for i in s:
  if a!=i:
    c+=1
  a=i
print(c)

Submission status: Wrong Answer

Solution code:
ret=0
s=input()
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    ret+=1
print(ret)

Submission status: Wrong Answer

Solution code:
s = input().strip()

prev = None
ans1, ans2 = 0, 0
for _s in s:
  if prev is None:
    prev = _s
  elif prev != _s:
    ans1 += 1
    prev = _s
prev = None
for _s in s[::-1]:
  if prev is None:
    prev = _s
  elif prev != _s:
    ans1 += 1
    prev = _s
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
S = input()
s = S[0:1]
ans = 0

for i in range(1,len(S)):
    if s != S[i:i+1]:
        ans += 1
        s = S[i:i+1]
        print(s)

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
s = S[0:1]
ans = 0

for i in range(1,len(S)-1):
    if s != S[i:i+1]:
        ans += 1
        s = S[i:i+1]

print(ans)

Submission status: Wrong Answer

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

s = list(input())
count = 0
turn = 'B'

if s.count('W') == len(s) or s.count('B') == len(s):
    print('0')
else:
    while s:
        if s[len(s) - 1] == turn:
            s.pop()
        else:
            count += 1
            if turn == 'B':
                turn = 'W'
            else:
                turn = 'B'
    print(count)

Submission status: Wrong Answer

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

s = list(input())
count = 0
turn = 'B'
while s:
    if s.count('B') == len(s) or s.count('W') == len(s):
        break

    if s[len(s) - 1] == turn:
        s.pop()
    else:
        count += 1
        if turn == 'B':
            turn = 'W'
        else:
            turn = 'B'

print(count)

Submission status: Wrong Answer

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

s = list(input())
count = 0
turn = 'B'
while s:
    if s[len(s) - 1] == turn:
        s.pop()
    else:
        count += 1
        if turn == 'B':
            turn = 'W'
        else:
            turn = 'B'

print(count)

Submission status: Wrong Answer

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


def leftside_reverse(s, turn):
    for num in range(len(s)):
        if s[num] == turn:
            break
        else:
            s[num] = turn

    return s


def rightside_reverse(s, turn):
    for num in range(len(s) - 1, -1):
        if s[num] == turn:
            break
        else:
            s[num] = turn

    return s


def function(s, first):
    count = 0
    turn = first

    while True:

        if s.count(first) == len(s):
            break

        if s[0] == turn:
            s = rightside_reverse(s, turn)
            count += 1
        else:
            s = leftside_reverse(s, turn)
            count += 1

        if turn == 'B':
            turn = 'W'
        else:
            turn = 'B'

    return count


if __name__ == '__main__':

    sb = list(input())
    sw = sb.copy()
    b = 'B'
    w = 'W'

    if sb.count(b) == len(sb) or sw.count(w) == len(sw):
        print('0')
    else:
        b_count = function(sb, b)
        w_count = function(sw, w)
        print(min(b_count, w_count))

Submission status: Wrong Answer

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

import sys


def leftside_reverse(s, turn):
    for num in range(len(s)):
        if s[num] == turn:
            break
        else:
            s[num] = turn

    return s


def rightside_reverse(s, turn):
    for num in range(len(s) - 1, -1):
        if s[num] == turn:
            break
        else:
            s[num] = turn

    return s


def function(s, first):
    count = 0
    turn = first

    while True:

        if s.count(first) == len(s):
            break

        if s[0] == turn:
            s = rightside_reverse(s, turn)
            count += 1
        else:
            s = leftside_reverse(s, turn)
            count += 1

        if turn == 'B':
            turn = 'W'
        else:
            turn = 'B'

    return count


if __name__ == '__main__':

    s = list(input())
    b = 'B'
    w = 'W'

    if s.count(b) == len(s) or s.count(w) == len(s):
        print('0')
    else:

        b_count = function(s, b)
        w_count = function(s, w)

        print(min(b_count, w_count))

Submission status: Wrong Answer

Solution code:
a = list(input())
ar = []
count = 1
n = a[0]
for i in range(1,len(a)):
    if n == "B":
        if a[i] == "B":
            count += 1
        else:
            ar.append(count)
            n = "W"
            count = 1
    else:
        if a[i] == "W":
            count += 1
        else:
            ar.append(count)
            n = "B"
            count = 1
    if i == len(a) - 1:
        ar.append(count)
print(len(ar) - 1)