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: Accepted

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

Submission status: Accepted

Solution code:
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i - 1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod
        
def iparse():
    return list(map(int, input().split()))

def RLE(s):
    res = []
    prev = ""
    cnt = 0
    for e in s:
        if prev == "":
            prev = e
            cnt += 1
        elif prev == e:
            cnt += 1
        else:
            res.append((cnt,prev))
            prev = e
            cnt = 1
    res.append((cnt,prev))
    return res


if __name__ == "__main__":
    s = input()
    rle = RLE(s)
    # print(rle)
    print(len(rle)-1)

Submission status: Accepted

Solution code:
#81 C - 一次元リバーシ
S = input()
S = S + '1'# 番兵

# 連続する文字をカウント
cnt = []
conti = 1
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        conti += 1
    else:
        cnt.append(conti)
        conti = 1
print(len(cnt)-1)

Submission status: Accepted

Solution code:
def main():
    *S, = input()
    c = S.pop()
    ans = 0
    while S:
        if (nc := S.pop()) == c:
            continue
        c = nc
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


S = LS2()
N = len(S)

print(sum(S[i] != S[i+1] for i in range(N-1)))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
now = -1
res = -1
for x in s:
    if now != x:
        res += 1
        now = x
print(res)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
ans=1
for i in range(n-1):
    if s[i]!=s[i+1]:
        ans+=1
print(ans-1)

Submission status: Accepted

Solution code:
S = list(input())
ans = 0

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

Submission status: Accepted

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(0); exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
cnt = 0
now = S[0]

for i in S:
    if i != now:
        now = i
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


S = LS2()
N = len(S)

print(sum(S[i] != S[i+1] for i in range(N-1)))

Submission status: Accepted

Solution code:
S = input()
ans = 0
tmp = S[0]
N = len(S)
if N == 1:
    print(0)
    exit()
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: Accepted

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

count=0
for i in range(N-1):
    if S[i]!=S[i+1]:
        count+=1

print(count)

Submission status: Accepted

Solution code:
from collections import Counter
S = input()

c = Counter(S)
if c['W'] == 0 or c['B'] == 0:
    print(0)
    exit()

now = ''
count = 0
for i in range(len(S)):
    if i == 0:
        now = S[i]
        continue
    if now == S[i]:
        continue
    else:
        count += 1
        now = S[i]
        continue

print(count)

Submission status: Accepted

Solution code:
def main():
    ss = input()
    put_stone = ''
    count = 0
    for stone in ss:
        if put_stone != '' and put_stone == stone:
            count += 1
        if stone == 'B':
            put_stone = 'W'
        else:
            put_stone = 'B'
    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(Sum)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    lst = [s[0]]

    for char in s[1:]:
        if lst[-1] != char:
            lst.append(char)

    ans = len(lst)-1
    print(ans)
main()

Submission status: Accepted

Solution code:
S = input()
prev = S[0]
cnt = 0
for s in S:
    if prev != s:
        cnt += 1
    prev = s
print(cnt)

Submission status: Accepted

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
s = input()
tmp = s[0]
cnt = 0
for c in s:
    if tmp != c:
        tmp = c
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
S = input()
now = 1
cnt = 0
for s in S:
    if s != now:
        now = s
        cnt += 1
print(cnt -1)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

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

Submission status: Accepted

Solution code:
S = input()
print(S.count("WB")+S.count("BW"))

Submission status: Accepted

Solution code:
from sys import exit
S = input()
#0回判定
x = len(S)
if S.count("B") == x or S.count("W") == x:
    print(0)
    exit()



cntw=0
for s in S.split("W"):
    if s:
        cntw += 1
cntb=0
for s in S.split("B"):
    if s:
        cntb += 1
print(abs(cntb - cntw) + min(cntb, cntw) * 2 - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby


# RUN LENGTH ENCODING str -> tuple
def runLengthEncode(S: str):
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, str(len(list(v)))))
    return res


# RUN LENGTH DECODING tuple -> str
def runLengthDecode(L: "list[tuple]"):
    res = ""
    for c, n in L:
        res += c * int(n)
    return res


# RUN LENGTH ENCODING str -> list
def rle_list(S: str):
    grouped = groupby(S)
    res = ""
    for k, v in grouped:
        res += k
    return res


def main():
    ss = input()
    rle = rle_list(ss)
    ans = len(list(rle)) - 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
S = input()
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: Accepted

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

Submission status: Accepted

Solution code:
S = input()
now = S[0]
cnt = 0
for s in S:
    if now == s:
        continue
    cnt += 1
    now = s
print(cnt)

Submission status: Accepted

Solution code:
s = input()
print(s.count("BW")+s.count("WB"))

Submission status: Accepted

Solution code:
s = input()
print(sum((s[i] != s[i+1] for i in range(len(s)-1))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
ans = 0
p = s[0]
for si in s:
    ans += p != si
    p = si
print(ans)

Submission status: Accepted

Solution code:
s=input()
ans=[]
pre=""
for i in s:
    if pre!=i:
        ans.append(i)
        pre=i

print(len(ans)-1)

Submission status: Accepted

Solution code:
S = input()
l = len(S)
ans = sum(a != b for a,b in zip(S[:l-1],S[1:]))
print(ans)

Submission status: Accepted

Solution code:
S = input()
c = 0

bs = '_'
for s in S:
  if s != bs:
    c += 1
    bs = s

print(c - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    S = input()
    pre = S[0]
    ans = 0
    for i, c in enumerate(S):
        if i == 0: continue
        if c != pre:
            ans += 1
            pre = c
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = s_input()
    ans = 0
    trial = s[0]
    for i in s[1:]:
        if trial != i:
            ans += 1
            trial = i
    print(ans)


if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
i=1
l=len(S)
res=0
f=S[0]

while i<l:
  if (S[i] == f):
        i+=1
  else:
    res+=1
    f=S[i]
    i+=1
print(res)

Submission status: Accepted

Solution code:
def main():
    s = input()
    print(sum([1 for i in range(len(s) - 1) if s[i] != s[i + 1]]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#
# abc047 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """BBBWW"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """WWWWWW"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """WBWBWBWBWB"""
        output = """9"""
        self.assertIO(input, output)


def resolve():
    S = list(input())

    i = 1
    while i < len(S):
        if S[i] == S[i-1]:
            del S[i]
        else:
            i += 1

    print(len(S)-1)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
S = list(input())
k = S.pop(0)
ii = 0
for i in S:
    if k == i:
        pass
    else:
        ii += 1
        k = i
print(ii)

Submission status: Accepted

Solution code:
from itertools import groupby
S = input()
gr = groupby(S)
print(len(list(gr))-1)

Submission status: Accepted

Solution code:
s=input()
c=0
t=s[0]
for k in s[1:]:
    if t!=k:
        t=k
        c+=1
print(c)

Submission status: Accepted

Solution code:
from itertools import groupby
s = input()
count = 0
for k, g in groupby(s):
    count += 1
print(count - 1)

Submission status: Accepted

Solution code:
s= input()
color = "chokudai"
d = []

for c in s:
    if c != color:
        d.append(c)
        color = c
print(len(d)-1)

Submission status: Accepted

Solution code:
from itertools import groupby

s = input()

cnt = 0

for k, g in groupby(s):
    cnt += 1

print(cnt - 1)

Submission status: Accepted

Solution code:
stack = []
for l in raw_input():
	if len(stack) == 0 or stack[-1] != l: stack.append(l)
print len(stack) -1

Submission status: Accepted

Solution code:
S = list(input())
count = 0
t = ''
for i in S:
    if t == i:
        continue
    else:
        t = i
        count += 1
print(count - 1)

Submission status: Accepted

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

Submission status: Accepted

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

s = input()
ans = 0 
for i in range(len(s)-1):
    if s[i+1] != s[i]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

print(res)

Submission status: Accepted

Solution code:
s = list(input())

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

print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
print(S.count('BW')+S.count('WB'))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
b = False
if s[0] == "B":
    b = True

ans = 0
for i in range(1, n):
    if b and s[i] == "W":
        b = False
        ans += 1
    elif not b and s[i] == "B":
        b = True
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
S=input()
print(S.count("BW")+S.count("WB"))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
l=len(s)

for i in range(l-1):
  if s[i]==s[i+1]:
    s[i]='0'
    
print(s.count('B')+s.count('W')-1)

Submission status: Accepted

Solution code:
# coding = SJIS

s = str(input())
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

s = S.replace('WB', 'W B').replace('BW', 'B W')
s = list(s.split())
print(len(s) -1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()+"p"
b=0
i=1
c=a[0]
while a[i]!="p":
  if a[i]!=c:
    c=a[i]
    b+=1
  i+=1
print(b)

Submission status: Accepted

Solution code:
S=list(input())
c=0;m=''
for i in S:
    if i!=m:
        m=i
        c+=1
print(c-1)

Submission status: Accepted

Solution code:
s = input()
cnt = 0
cur = s[0]
strk = 1

for i in range(1, len(s)):
    if s[i] == cur:
        strk += 1
    else:
        cnt += 1
        cur = s[i]
        strk = 1

cnt += 1

print(cnt-1)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
print(sum(a != b for a, b in zip(s[1:], s[:-1])))

Submission status: Accepted

Solution code:
# C - 一次元リバーシ
def main():
    s = input()
    t = s[0]
    cnt = 1

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

if __name__ ==  "__main__":
    main()

Submission status: Accepted

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

ans=0
for i in range(n-1):
    if s[i+1]!=s[i]:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
s = input()
ch = s[-1]
index = len(s) - 1
answ = 0
while index >= 0:
    if s[index] != ch:
        answ += 1
        ch = 'B' if ch == 'W' else 'W'
    else:
        index -= 1
print(answ)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
color = s[0]
cnt = 0
for i in range(1,len(s)):
    if color != s[i]:
        color = s[i]
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
S = input()
X = S[0]
ans = 0
while 1:    
    for i in range(len(S)):
        if S[i] != X:
            ans += 1
            X =S[i]
            S = S[i:]
            break
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
S=input()

if len(set(S))==1:
  print(0)
  exit()
  
count = 0
for i in range(1,len(S)):
  if S[i] != S[i-1]:count += 1
    
print(count)

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

Solution code:
s=input()
c=0
re=s[0]
n=len(s)
for i in range(1,n):
  if s[i]!=re:
    c+=1
  re=s[i]
print(c)

Submission status: Accepted

Solution code:
s = input()
print(s.count('WB')+s.count('BW'))

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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 prev == "":
        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: Accepted

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

# from numba import njit

# input = stdin.readline

def calcGroup(s):
  whiteCount = 0
  blackCount = 0
  prev = ""
  for i in range(len(s)):
    if s[i] == prev:
      pass
    else:
      if s[i] == "W":
        whiteCount += 1
      elif s[i] == "B":
        blackCount += 1
      else:
        raise ValueError
    prev = s[i]
  return whiteCount,blackCount

# @njit
def solve(s):
  white,black = calcGroup(s)
  if abs(white-black) == 0:
    return (white-1)*2+1
  else:
    return min(white,black)*2



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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
sikii = [0]*(n+1)
for i in range(n-1):
    if s[i] != s[i+1]:
        sikii[i+1] = 1
#print(sikii)
print(sum(sikii))

Submission status: Accepted

Solution code:
s = input()
ans = 0
iro = ''

for i in range(len(s)):
    if i == 0:
        iro = s[0]
    elif iro != s[i]:
        ans += 1
        iro = s[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

pivot = s[0]
result = 0
for c in s:
  if pivot != c:
    pivot = c
    result += 1
print(result)

Submission status: Accepted

Solution code:
s = input()

min_value = 10 ** 9

# 左端に置く場合
pivot = s[0]
result = 0
for c in s:
  if pivot != c:
    pivot = c
    result += 1
min_value = min(min_value, result)

# 右端に置く場合
result = 0
for c in reversed(s):
  if pivot != c:
    pivot = c
    result += 1
min_value = min(min_value, result)
print(min_value)

Submission status: Accepted

Solution code:
c=0
s=input()
b=s[0]
for m in s:
  if m!=b:
    c+=1
    b=m
print(c)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())+['END']
lis = []
now = S[0]
for s in S[1:]:
    if s!=now:
        lis.append(now)
        now = s

print(len(lis)-1)

Submission status: Accepted

Solution code:
s = str(input())


result = 0


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

print(result)

Submission status: Accepted

Solution code:
s = list(input())
s.append('X')
cnt = 0
for n in range(len(s)-1):
	if s[n] != s[n+1]:
		cnt += 1
print(cnt - 1)

Submission status: Accepted

Solution code:
S = input()
color = S[0]
cnt = 0
for i in S[1:]:
    if i != color:
        cnt += 1
        color = i
print(cnt)

Submission status: Accepted

Solution code:
S = input()
pre = "X"
B, W = 0, 0
for s in S:
    if s != pre:
        if s == "B":
            B += 1
        else:
            W += 1
        pre = s

if B == 0 or W == 0:
    print(0)
elif B == W:
    print(B * 2 - 1)
else:
    x, y = min(B, W), max(B, W)
    print(x * 2)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()

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

print(cnt)

Submission status: Accepted

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

tmp = S[0]
cnt = 0
for i in range(1, len(S)):
    if S[i] == tmp:
        continue
    else:
        tmp = S[i]
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
S=str(input())
n=0
ch=S[0]
for s in S:
    if ch!=s:
        n+=1
    ch=s
print(n)

Submission status: Accepted

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]

print(r)

Submission status: Accepted

Solution code:
S=input()

X=0
for i in range(1,len(S)):
    if S[i]!=S[i-1]:
        X+=1
print(X)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=input()
cnt=0
tmp=A[0]
for i in A:
   if tmp!=i:
      cnt+=1
      tmp=i
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
print(sum(s[i - 1] != s[i] for i in range(1, len(s))))

Submission status: Accepted

Solution code:
from itertools import groupby

S=input()
G=groupby(S)
g=[len(list(i)) for i,_ in G]
print(sum(g)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections


def main():
    S = input()
    cnt = 0
    tmp = ""
    for s in S:
        if s != tmp:
            cnt += 1
        tmp = s

    print(cnt - 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

# In[7]:


S = input()


# In[8]:


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


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
if len(S)==max(S.count('W'),S.count('B')):
    print(0)
    exit()
else:
    t=''
    cnt=0
    for i in S:
        if i!=t:
            cnt+=1
            t=i

    print(cnt-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    S = input()
    print(sum(1 for i in range(len(S)-1) if S[i] != S[i+1]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    S = input()
    # 色が変わる回数=色を統一するために必要な手数
    prev_color = S[0]
    color_change_count = 0
    for s in S:
        if s != prev_color:
            color_change_count += 1
            prev_color = s
    print(color_change_count)

resolve()

Submission status: Accepted

Solution code:
from itertools import groupby
S=input()
G=groupby(S)
print(len(list(G))-1)

Submission status: Accepted

Solution code:
S = input()
change = 0
flag = S[0]
for i in S[1:]:
    if i != flag:
        change +=1
        flag = i
print(change)

Submission status: Accepted

Solution code:
s = input()

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