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()
total=0
rec=s[0]
for i in range(1,len(s)):
    if rec!=s[i]:
        rec=s[i]
        total+=1
print(total)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
s=input().rstrip()
t=s[0]
ans=0
for i in range(1,len(s)):
    if s[i]!=t:
        t=s[i]
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

check=S[0]
S_=check
for s in S[1:]:
    if check != s:
        check = s
        S_+=check
        
print(len(S_)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

def calculate(s):
    categories = 0
    for i in range(len(s)):
        if i == 0:
            continue

        if s[i] != s[i-1]:
            categories += 1
            continue

    print(categories)



calculate(S)

Submission status: Accepted

Solution code:
# BWBWB と BWWBBBBWWWWWWBBBBB を一色にする手順は同じ。
from itertools import groupby

S = input()
grp = [k for k, _ in groupby(S)]
print(len(grp) - 1)

Submission status: Accepted

Solution code:
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    print(len(list(groupby(S))) - 1)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

current = S[0]
ans = 0
for s in S:
    if s != current:
        ans += 1
        current = s

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    s = input()
    seg = 1
    for i in range(1, len(s)):
        if s[i] != s[i-1]:
            seg += 1
    print(seg - 1)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

Submission status: Accepted

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

S = LS2()

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=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 n in range(len(S)-1):
  if S[n] != S[n+1]:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
res = 0
st = s[0]

for v in s:
    if st != v:
        res += 1
        st = v
print(res)

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:
# https://atcoder.jp/contests/abc047/tasks/arc063_a
# 連長圧縮すれば簡単
# 圧縮後の文字列長-1となる


# def run_length_encoding(s):
#     '''連長圧縮を行う
#     s ... iterable object e.g. list, str
#     return
#     ----------
#     s_composed,s_num,s_idx
#     それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
#     s_composed, s_sum = [], []
#     s_idx = [0]
#     pre = s[0]
#     cnt = 1
#     for i, ss in enumerate(s[1:], start=1):
#         if pre == ss:
#             cnt += 1
#         else:
#             s_sum.append(cnt)
#             s_composed.append(pre)
#             s_idx.append(i)
#             cnt = 1
#             pre = ss
#     s_sum.append(cnt)
#     s_composed.append(pre)
#     # assert len(s_sum) == len(s_composed)
#     return s_composed, s_sum, s_idx


def run_length_encoding(s):
    '''連長圧縮を行う
    s ... iterable object e.g. list, str
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
    from itertools import groupby
    s_composed, s_sum = [], []
    s_idx = [0]
    for k, v in groupby(s):
        s_composed.append(k)
        # n = len(list(v))
        # s_sum.append(n)
        # s_idx.append(s_idx[-1] + n)

    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx


S_composed, _, _ = run_length_encoding(input())
print(len(S_composed) - 1)

Submission status: Accepted

Solution code:
def run_length_encoding(s):
    '''連長圧縮を行う
    s ... iterable object e.g. list, str
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
    from itertools import groupby
    s_composed, s_sum = [], []
    s_idx = [0]
    for k, v in groupby(s):
        s_composed.append(k)
        n = len(list(v))
        s_sum.append(n)
        s_idx.append(s_idx[-1] + n)

    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx


S_composed, _, _ = run_length_encoding(input())
print(len(S_composed) - 1)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc047/tasks/arc063_a
# 連長圧縮すれば簡単
# 圧縮後の文字列長-1となる


def run_length_encoding(s):
    '''連長圧縮を行う
    s ... iterable object e.g. list, str
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
    s_composed, s_sum = [], []
    s_idx = [0]
    pre = s[0]
    cnt = 1
    for i, ss in enumerate(s[1:], start=1):
        if pre == ss:
            cnt += 1
        else:
            s_sum.append(cnt)
            s_composed.append(pre)
            s_idx.append(i)
            cnt = 1
            pre = ss
    s_sum.append(cnt)
    s_composed.append(pre)
    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx


# def run_length_encoding(s):
#     '''連長圧縮を行う
#     s ... iterable object e.g. list, str
#     return
#     ----------
#     s_composed,s_num,s_idx
#     それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
#     from itertools import groupby
#     s_composed, s_sum = [], []
#     s_idx = [0]
#     for k, v in groupby(s):
#         s_composed.append(k)
#         n = len(list(v))
#         s_sum.append(n)
#         s_idx.append(s_idx[-1] + n)

#     # assert len(s_sum) == len(s_composed)
#     return s_composed, s_sum, s_idx


S_composed, _, _ = run_length_encoding(input())
print(len(S_composed) - 1)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc047/tasks/arc063_a
# 連長圧縮すれば簡単
# 圧縮後の文字列長-1となる


# def run_length_encoding(s):
#     '''連長圧縮を行う
#     s ... iterable object e.g. list, str
#     return
#     ----------
#     s_composed,s_num,s_idx
#     それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
#     s_composed, s_sum = [], []
#     s_idx = [0]
#     pre = s[0]
#     cnt = 1
#     for i, ss in enumerate(s[1:], start=1):
#         if pre == ss:
#             cnt += 1
#         else:
#             s_sum.append(cnt)
#             s_composed.append(pre)
#             s_idx.append(i)
#             cnt = 1
#             pre = ss
#     s_sum.append(cnt)
#     s_composed.append(pre)
#     # assert len(s_sum) == len(s_composed)
#     return s_composed, s_sum, s_idx


def run_length_encoding(s):
    '''連長圧縮を行う
    s ... iterable object e.g. list, str
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
    from itertools import groupby
    s_composed, s_sum = [], []
    s_idx = [0]
    for k, v in groupby(s):
        s_composed.append(k)
        n = len(list(v))
        s_sum.append(n)
        s_idx.append(s_idx[-1] + n)

    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx


S_composed, _, _ = run_length_encoding(input())
print(len(S_composed) - 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 = 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:
import sys

def main(s):
    counter=0
    cf=s[0]
    for x in s:
        if cf!=x:
            cf=x
            counter+=1
    return counter

s=sys.stdin.readline().strip()
print(main(s))

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

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:
import itertools
print(len(list(itertools.groupby(input())))-1)

Submission status: Accepted

Solution code:
S=input()
ans=len(S)
now=S[0]
for s in S:
    ans-=s==now
    now=s
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:
from collections import deque
S = deque(list(input()))

ans = 0
s = S.popleft()
while S:
    n = S.popleft()
    if s != n:
        ans += 1
        s = n
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()
pres = S[0]
ans = 0
for s in S[1:]:
    if pres == s:
        continue
    else:
        pres = s
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import threading
import sys


def main():
    def solve(n):
        if n == 1:
            return 0
        else:
            if S[n - 2] == S[n - 1]:
                return solve(n - 1)
            else:
                return solve(n - 1) + 1

    S = input()
    first_s = S[0]
    S = [1 if first_s == s else 0 for s in S]

    print(solve(len(S)))


if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024 * 2)
    threading.stack_size(128 * 1024 * 1024 * 2)
    threading.Thread(target=main).start()

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = input()

i = 1
count = 1
while i < len(S):
    if S[i] != S[i - 1]:
        count += 1
    i += 1
print(count - 1)

Submission status: Accepted

Solution code:
s = input()

print(sum(s[i] != s[i - 1] for i in range(1, len(s))))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s = input()

stone = [s[0]]
for i in range(1,len(s)):
    if s[i] != s[i - 1]:
        stone.append(s[i])
print(len(stone) - 1)

Submission status: Accepted

Solution code:
s = input()

stone = [s[0]] + [s[i] for i in range(1, len(s)) if s[i] != s[i - 1]]
print(len(stone) - 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:
s=input()

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:
a = input()
cnt = 0
for i in range(len(a)):
  if i == 0:
    continue
  if a[i] != a[i-1]:
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
sys.setrecursionlimit(10 ** 6)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

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()
c = 0
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        c += 1

print(c)

Submission status: Accepted

Solution code:
S = str(input())

now = S[0]
ans = 0

for i in range(1, len(S)):
  #print(i, end = "")
  if S[i] != now:
    ans += 1
    now = S[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0
bef = s[0]
for c in s[1:]:
    if bef != c:
        ans += 1
    bef = c

print(ans)

Submission status: Accepted

Solution code:
import re

S = input()
S = re.sub('[B]{2,}', 'B', S)
S = re.sub('[W]{2,}', 'W', S)

print(len(S)-1)

Submission status: Accepted

Solution code:
s = input()
ans = 0

before = s[0]

for c in s[1:]:
    if c != before:
        ans += 1
        before = c

print(ans)

Submission status: Accepted

Solution code:
S = input()

now = S[0]
N = len(S)
ans = 0
for i in range(1,N):
  if S[i] != now:
    ans += 1
    now = S[i]
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 = list(input())
c=0
first = S[0]
for i in range(1,len(S)):
  if S[i] != first:
    c+=1
    first = S[i]
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import groupby
    s = input()
    ans = len(list(groupby(s))) - 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
now = S[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()
answer = 0
present_color = ''
for i in range(len(S)):
    if i == 0:
        present_color = S[i]
        continue
    if present_color != S[i]:
        answer += 1
    else:
        pass
    present_color = S[i]
print(answer)

Submission status: Accepted

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

seg = []
for i in range(n-1):
    if l[i] != l[i+1]:
        seg.append(i)
print(len(seg))

Submission status: Accepted

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

idx = 0
seg = []
while idx < n:
    while idx < n-1 and l[idx] == l[idx+1]:
        idx+=1
    seg.append(idx)
    idx+=1
print(len(seg)-1)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = input()
pre = s[0]
if len(s) == 1:
    print(0)
    sys.exit()
else:
    ans=0
    for i in range(1,len(s)):
        if pre != s[i]:
            ans+=1
            pre = s[i]
    print(ans)

Submission status: Accepted

Solution code:
import itertools

S=input()

S_=itertools.groupby(S)
cnt=-1
for key,gr in S_:
	cnt+=1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if N==1:
    print(0)
else:
    b = S[0]
    ans = 0
    for i in S[1:]:
        if i!=b:
            ans += 1
            b = i
    print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = readline().decode().rstrip()
cnt = 0
for i in range(1, len(s)):
    if s[i - 1] != s[i]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc047/tasks/arc063_a
# 連長圧縮すれば簡単
# 圧縮後の文字列長-1となる


def run_length_encoding(s):
    '''連長圧縮を行う
    s ... iterable object e.g. list, str 
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
    s_composed, s_sum = [], []
    s_idx = [0]
    pre = s[0]
    cnt = 1
    for i, ss in enumerate(s[1:], start=1):
        if pre == ss:
            cnt += 1
        else:
            s_sum.append(cnt)
            s_composed.append(pre)
            s_idx.append(i)
            cnt = 1
            pre = ss
    s_sum.append(cnt)
    s_composed.append(pre)
    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx


S_composed, _, _ = run_length_encoding(input())
print(len(S_composed) - 1)

Submission status: Accepted

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

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

    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    S = list(input())
    r = 0

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

    S.reverse()
    l = 0

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

    print(min(r, l))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

if s[-1] == 'B':
   new = 'W'
else:
   new = 'B'

if s == s[0] * len(s):
   print(0)
   exit()

ans = 0
for i in reversed(range(len(s)-1)):
   if s[i] == new:
      ans += 1
      if new == 'B':
         new = 'W'
      else:
         new = 'B'
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s=input()
a=s.count('BW')
b=s.count('WB')

print(a+b)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    S = input().strip()
    ans = 0
    for i in range(1, len(S)):
        if S[i] != S[i-1]:
            ans += 1
    return ans


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

Submission status: Accepted

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    s = str(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    l = len(s)
    ans = 0
    for i in range(l-1):
        if s[i] != s[i+1]:
            ans += 1
    print(ans)

main()

Submission status: Accepted

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	s_list = list(S())
	s_list2 = []
	s_list2.append(s_list.pop(0))
	for s in s_list:
		if s_list2[-1] != s:
			s_list2.append(s)
	print(len(s_list2)-1)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s=input()
cnt=0
i=0
j=s[0]
n=len(s)
while True:
  for k in range(i+1,n):
    if s[k]!=j:
      cnt+=1
      j=s[k]
      i=k
      break
  else:break
print(cnt)

Submission status: Accepted

Solution code:
s= input()

now = s[0]
ans = 0
for i in range(1,len(s)):
    if now == s[i]:
        pass
    elif now != s[i]:
        ans += 1
        flg = 1
        now = s[i]

print(ans)

Submission status: Accepted

Solution code:
s= input()

now = s[0]
ans = 0
flg = 0
for i in range(1,len(s)):
    if flg == 0:
        if now == s[i]:
            pass
        elif now != s[i]:
            ans += 1
            flg = 1
            now = s[i]

    else:
        if now == s[i]:
            pass
        elif now != s[i]:
            ans += 1
            flg = 0
            now = s[i]
            
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
from itertools import combinations,permutations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input()
cnt = 0
for i in range(len(S)):
    if i == 0:
        prv = S[i]
    else:
        if prv != S[i]:
            cnt += 1
            prv = S[i]
        else:
            pass
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
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:
S = input().strip()
N = len(S)
cur = 0
cnt = 0
for i in range(1,N):
    if S[i]!=S[cur]:
        cnt += 1
        cur = i
print(cnt)

Submission status: Accepted

Solution code:
S = input()
b = S[0]
x = [b]
for s in S[1:]:
    if b == s: continue
    x.append(s)
    b = s
print(len(x)-1)

Submission status: Accepted

Solution code:
s = str(input())
temp = s[0]
X = []
cnt = 0
for i in range(len(s)):
    if s[i] == temp:
        cnt += 1
    else:
        temp = s[i]
        X.append(cnt)
        cnt = 1
else:
    X.append(cnt)
print(len(X)-1)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

S = ins()


def solve():
    N = len(S)
    i = 0
    j = 1
    flip = 0
    while j < N:
        while j < N and S[i] == S[j]:
            j += 1
        if j == N:
            break
        flip += 1
        i = j
        j += 1

    return flip


print(solve())

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *
from itertools import permutations

S = input()[:-1]
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 re
s = input()
s = re.sub('[W]+', 'W', s)
s = re.sub('[B]+', 'B', s)
ans = len(s) - 1
print(ans)

Submission status: Accepted

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

 
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def BWstripper(S):
  BWarray=[]
  while (len(S) != 0):
    initial = S[0]
    tmp=""
    while (S[0] == initial):
      tmp+=S[0]
      S=S.lstrip(initial)
      if len(S) == 0:
        break
    BWarray.append(tmp)
  return BWarray
S=input()
stripped = BWstripper(S)
print(len(stripped)-1)

Submission status: Accepted

Solution code:
S = input()

if len(S) == 1:
    print(0)
    exit()

c0 = S[0]
cnt = 0
for c in S[1:]:
    if c != c0:
        c0 = c
        cnt += 1 
print(cnt)

Submission status: Accepted

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