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:
# 2019/06/04
# AtCoder Beginner Contest 047 - C

# Input
s = input()

# Init
ws = s[0]
scnt = 0

for i in range(1, len(s)):
    # Change color: Count up
    if ws != s[i]:
        ws = s[i]
        scnt += 1

# Output
print(scnt)

Submission status: Accepted

Solution code:
# ABC047C - 一次元リバーシ / 1D Reversi
s = input()
print(s.count("BW") + s.count("WB"))

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()
ans = 0
for i in range(len(s) - 1):
    if s[i] == 'B' and s[i + 1] == 'W':
        ans += 1
    elif s[i] == 'W' and s[i + 1] == 'B':
        ans += 1
        
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 = str(input())

S_W = [s for s in S.split('W') if s ]
S_B = [s for s in S.split('B') if s ]

W = len(S_W)
B = len(S_B)

print(W + B - 1)

Submission status: Accepted

Solution code:
from itertools import groupby

s = input()

cnt = 0
for i in groupby(s):
  cnt += 1

print(cnt - 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()
print(S.count('BW') + S.count('WB'))

Submission status: Accepted

Solution code:
S=input()
N=len(S)
if S=="B"*N or S=="W"*N:
    print(0)
    quit()
tmp=S[0]
ans=0
for i in S:
    if tmp!=i:
        ans+=1
        tmp=i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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


solve()

Submission status: Accepted

Solution code:
S = input()
S_list = list(S)

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

Submission status: Accepted

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

Submission status: Accepted

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

print(b)

Submission status: Accepted

Solution code:
S = input()
print( sum([ 1 for x, y in zip(S[:-1], S[1:]) if x != y]) )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - 一次元リバーシ / 1D Reversi
https://atcoder.jp/contests/abc047/tasks/arc063_a

"""
import sys


def solve(S):
    prev = S[0]
    ans = 0
    for ch in S:
        if ch != prev:
            ans += 1
        prev = ch
    return ans


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

S = list(input().strip())

c = [0] * 4
t = "B"
for i in range(len(S)):
    if S[i] != t:
        t = S[i]
        c[0] += 1
        
t = "B"
for i in reversed(range(len(S))):
    if S[i] != t:
        t = S[i]
        c[1] += 1

t = "W"
for i in range(len(S)):
    if S[i] != t:
        t = S[i]
        c[2] += 1
        
t = "W"
for i in reversed(range(len(S))):
    if S[i] != t:
        t = S[i]
        c[3] += 1
            
print(min(c))

Submission status: Accepted

Solution code:
s=input()
ans=[0]
for i in range(1, len(s)):
	if s[i] == s[i-1]:
		ans.append(ans[i-1])
	else:
		ans.append(ans[i-1]-1)
print(-min(ans))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
count=0
for i in range(n-1):
    if (s[i]=='B' and s[i+1]=='W') or (s[i]=='W' and s[i+1]=='B'):
        count+=1
print(count)

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:
from sys import stdin
S = list(stdin.readline().rstrip())
l = len(S)
ans = 0
for i in range(1,l):
    if S[i] != S[i-1]:
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
import re
s=input()
f=[g for g in re.finditer(s[0]+'{1,}', s)]
k='B' if s[0]=='W'else 'W'
s=[g for g in re.finditer(k+'{1,}', s)]
print(len(f)+len(s)-1)

Submission status: Accepted

Solution code:
S = input()

print(S.count("BW") + S.count("WB"))

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:
board1d = [c for c in input()]

ph = board1d.pop()
count = 0
while board1d:
    ph_post = board1d.pop()
    if ph_post != ph:
        count += 1
    ph = ph_post
print(count)

Submission status: Accepted

Solution code:
s = input()

ss = []

pre = s[0]
cnt = 0
for c in s:
    if c==pre:
        cnt+=1
    else:
        ss.append(cnt)
        cnt=1
        pre = c
ss.append(cnt) 
print(len(ss)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
LIS = []
for i in input():
    LIS.append(i)
A = 0
for i in range(len(LIS)-1):
    if LIS[i] != LIS[i+1]:
        A += 1
print(A)

Submission status: Accepted

Solution code:
S = input()
nums = []
c = 0
n = S[0]
for s in S:
    if s == n:
        c += 1
    else:
        nums.append(c)
        c = 1
        n = s
nums.append(c)
print(len(nums)-1)

Submission status: Accepted

Solution code:
S = input()
cnt = 0
last = ''
for i in S:
    if(last != i):
        cnt += 1
    last = i
print(cnt-1)

Submission status: Accepted

Solution code:
S = input()
num = 0
now = S[0]
for s in S:
    if s == now:
        continue
    if now == "B":
        now = "W"
    else:
        now = "B"
    num += 1
print(num)

Submission status: Accepted

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

def solve(S):
    count = 0
    mark = S[0]
    for i in range(1, len(S)):
        if(S[i] == mark):
            continue
        else:
            mark = S[i]
            count += 1
    print(count)
    
if __name__ == '__main__':
    S = list(input())
    
    solve(S)

Submission status: Accepted

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

Submission status: Accepted

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

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:


def read_input():
    s = input().strip()
    return s

def submit():
    s = read_input()

    count_marble = 0
    for bigram in zip(s, s[1:]):
        if bigram[0] != bigram[1]:
            count_marble += 1

    print(count_marble)


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
S = input()

ans = 0
pre = S[0]
for i in S[1:]:
    if i != pre:
        ans += 1
    pre = i

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
cum_s = []
count_b, count_w = 0, 0
for s in S:
  if s == 'B':
    count_b += 1
    if count_w > 0:
      cum_s.append(count_w)
      count_w = 0
  else:
    count_w += 1
    if count_b > 0:
      cum_s.append(count_b)
      count_b = 0
cum_s.append(max(count_b, count_w))
print(len(cum_s)-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]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=input()
ans=1
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: Accepted

Solution code:
S=input()

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

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = str(input().strip())

    s0 = S[0]
    cnt = 0
    for s in S:
        if s != s0:
            cnt += 1
            s0 = s

    return cnt


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

Submission status: Accepted

Solution code:
s = input().rstrip()
prev = s[0]
count = 0
for c in s[1:]:
    if c != prev:
        prev = c
        count += 1
    else:
        pass
print(count)

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


ans = S.count("WB") + S.count("BW")
print(ans)

Submission status: Accepted

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


ans = sum([1 for i in range(N-1) if S[i]!=S[i+1]])
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()
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()
counter = 1
moji = S[0]
for char in S:
    if char != moji:
        counter +=  1
        moji = char
        
print(counter - 1)

Submission status: Accepted

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

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

Submission status: Accepted

Solution code:
s=input()
while "BB" in s or "WW" in s:
    s=s.replace("BB","B").replace("WW","W")
print(len(s)-1)

Submission status: Accepted

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

s = input()

result1 = s.count("BW")
result2 = s.count("WB")

print(result1 + result2)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s = list(input())
c = []
temp = "A"
for s_ in s:
    if temp != s_:
        c.append(s_)
        temp = s_
print(len(c)-1)

Submission status: Accepted

Solution code:
s = str(input())

if len(s) == 1:
    print(0)

else:
    x = s[0]
    cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
if s[0]=="W":
    j="B"
else:
    j="W"
ans=-1   
for i in s:
    if i!=j:
        ans+=1
        j=i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(str(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:
#C問題
S=str(input())
Slist=list(S)
Slen=len(Slist)
count=0
mae=""
for i in range(Slen):
    if i == 0:
        mae=Slist[0]
    else:
        if Slist[i] == mae:
            pass
        else:
            mae=Slist[i]
            count+=1
print(count)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()

now = ""
count = 0

for stone in S:
	if stone != now:
		count += 1
	now = stone
print(count-1)

Submission status: Accepted

Solution code:
def _1d_reversi(S: str) -> int:
    n = len(S)
    return sum(S[i] != S[i-1] for i in range(1, n))


if __name__ == "__main__":
    S = input()
    ans = _1d_reversi(S)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(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 = 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:
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # s = input().rstrip()
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 1文字ずつ標準入力を配列として読み込み
    # s = list(input().rstrip())
    # N, A = [int(_) for _ in input().split()]
    # X = [int(_) for _ in input().split()]
    S = list(input().rstrip())
    tmp_color = S[0]
    ans=0 
    for i in range(len(S)):
        if(tmp_color != S[i]):
            tmp_color = S[i]
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = input()

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    c = s.count("0")
    print(2*min(c,len(s)-c))
    return

#B
def B():
    n = I()
    h = LI()
    ans = 0
    m = min(h)
    while m:
        ans += m
        k = max(h)
        for i in range(n):
            if h[i] >= m:
                h[i] -= m
                if h[i]:k = min(k,h[i])
            else:break
        m = k
    print(ans)
    return

#C
def C():
    n,k = LI()
    x = LI()
    ans = float("inf")
    j = bisect.bisect_left(x,0)
    if n == 1:
        print(abs(x[0]))
        quit()
    if j < n:
        if x[j] == 0:
            k -= 1
            x.pop(j)
            n -= 1
    for i in range(n):
        if i < j:
            if abs(i-j) > k:continue
            elif abs(i-j) == k:ans = min(ans,abs(x[i]))
            elif k+i-1 < n:
                ans = min(ans,abs(x[i])+x[k+i-1]-x[i])
        else:
            if abs(i-j)+1 > k:continue
            elif abs(i-j)+1 == k:ans = min(ans,x[i])
            elif i-k+1 >= 0:
                ans = min(ans,abs(x[i])+x[i]-x[i-k+1])

    print(ans)
    return

#D
def D():
    n = I()
    a = LI()
    ans = 0
    p = [1<<i for i in range(100)]
    for i in range(n):
        l = 0
        r = 100
        while r-l > 1:
            m = (l+r)//2
            if a[i]%p[m] == 0:
                l = m
            else:
                r = m
        ans += l
    print(ans)
    return

#E
def E():
    s = LI()
    s.sort()
    ans = s[2]-s[1]
    s[0] += s[2]-s[1]
    s[1] = s[2]
    if s[0]%2 != s[1]%2:
        ans += (s[1]+1-s[0])//2+1
    else:
        ans += (s[1]-s[0])//2
    print(ans)
    return

#F
def F():
    n = I()
    s = SR(n)
    for i in range(n):
        d = defaultdict(int)
        for j in range(len(s[i])):
            d[s[i][j]] += 1
            s[i][j] += str(d[s[i][j]])
    ans = set(s[0])
    for i in range(1,n):
        ans = ans&set(s[i])
    ans = list(ans)
    ans.sort()
    for i in ans:
        print(i[0],end = "")
    print()
    return

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

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

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

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

S = input()

a = S.count("BW")
b = S.count("WB")

print(a+b)

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


stack = []
stack.append(S[0])
count = 0
for c in S:
    if stack[-1] != c:
        count += 1
        stack.append(c)
ans = 10 ** 18
ans = min(ans, count)

count = 0
stack = []
stack.append(S[-1])
for c in S[::-1]:
    if stack[-1] != c:
        count += 1
        stack.append(c)

ans = min(ans, count)

print(ans)

Submission status: Accepted

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

print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:

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)
    ans = s.count('BW')*2-1
    print(ans if s[-1] != 'B' else ans+1)
else:
    s = re.sub(r'B+', 'B', s)
    s = re.sub(r'W+', 'W', s)
    ans = s.count('WB')*2-1
    print(ans if s[-1] != 'W' else ans+1)

Submission status: Accepted

Solution code:
s,ans=input(),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())
Ans = []
count = 0
tmp = S[0]
for i in range(1,len(S)):
    if S[i] != tmp:
        Ans.append(1)
    tmp = S[i]
print(len(Ans))

Submission status: Accepted

Solution code:
from itertools import groupby

S=input()
answer = sum([1 for _ in groupby(S)]) -1

print(answer)

Submission status: Accepted

Solution code:
import numpy as np

S=input()
S=np.array([1 if s=='B' else 0 for s in S])

print(np.abs(np.diff(S)).sum())

Submission status: Accepted

Solution code:
S=input()

answer=0
prev=S[0]
for s in S:
  if s!=prev:
    answer+=1
  prev=s

print(answer)

Submission status: Accepted

Solution code:
from itertools import groupby

S=input()
answer = -1
for _ in groupby(S):
  answer+=1
  
print(answer)

Submission status: Accepted

Solution code:
S = input()
new_S = []
now = ''
for x in S:
    if x == now:
        pass
    else:
        new_S.append(x)
    now = x
print(len(new_S)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

cnt = 0
now = s[0]

for x in s:
    if x != now:
        now = x
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def main():
    S = input()
    prev = ""
    ans = 0
    for c in S:
        if c != prev:
            ans += 1
        prev = c
    print(ans-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
keepcount = "P"
count = 0
for i in S:
    if keepcount == "P":
        keepcount = i
    elif keepcount != i:
        keepcount = i
        count += 1

print(count)

Submission status: Accepted

Solution code:
S = input()

pre = S[0]
res = 0

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

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 = [str(_) for _ in input()]
tmp = S[0]
cnt = 0

for i in S:
    if i != tmp:
        cnt += 1
    tmp = i

print(cnt)

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

rem = pow(10,9)+7

#n = ip()                                     #入力整数1つ
#x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(x)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
s = 0
for i in range(len(a)-1):
    if a[i] != a[i+1]:s+=1
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

now = ""
counter = 0
for w in s:
    if now != w:
        counter += 1
    now = w

print(counter - 1)

Submission status: Accepted

Solution code:
s = list(input())
t = []
for i in range(len(s)):
    if i == len(s)-1:
        t.append(s[i])
    elif s[i] == s[i+1]:
        continue
    else:
        t.append(s[i])

print(len(t)-1)

Submission status: Accepted

Solution code:
#ABC047C
S=input()
n=S[0]
ans=0
for s in S:
    if n!=s:
        n=s
        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:
X = list(input())

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

Submission status: Accepted

Solution code:
s = list(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:
def c_1d_reversi(S):
    # 端の同じ色の石は1個の石を置けばひっくり返せる
    # 連続した石をひとまとめにしたとき、何個の石があるかが解を導く
    from itertools import groupby
    return len(list(groupby(S))) - 1

S = input()
print(c_1d_reversi(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

l = 0

for c1, c2 in zip(S, S[1:]):
    if c1 == c2:
        l += 1

result = len(S) - l - 1

print(result)

Submission status: Accepted

Solution code:
print(sum(map(input().count,["WB","BW"])))

Submission status: Accepted

Solution code:
from itertools import*;print(len(list(groupby(input())))-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=input()+"E"

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

Submission status: Accepted

Solution code:
s=input()
flag=2
counter=0
for i in s:
    now_flag=flag
    if i=="B":
        flag=0
    else:
        flag=1
    if now_flag!=flag:
        counter+=1
print(counter-1)

Submission status: Accepted

Solution code:
S = 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 = input()
ans = 0
now = s[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 = input()

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

Submission status: Accepted

Solution code:
[print(len(list(i.groupby(input())))-1)for i in[__import__('itertools')]]

Submission status: Accepted

Solution code:
[print(len(list(i.groupby(input())))-1) for i in [__import__('itertools')]]

Submission status: Accepted

Solution code:
from sys import stdin, stderr, setrecursionlimit, exit
setrecursionlimit(2147483647)
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

ans = 0
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
import sys
# A,B,C = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
# L = len(S)
# T = str(input())
ans = 0
prev = S[0]
for s in S:
    if(s != prev):
        ans+=1
    prev = s
print(ans)

Submission status: Accepted

Solution code:
s=input()
x=s[0]
ans=0
for i in range(1,len(s)):
    if x!=s[i]:
        ans+=1
        x=s[i]
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:
s = input()
a1 = s.count('BW')
a2 = s.count('WB')
print(a1 + a2)

Submission status: Accepted

Solution code:
s = input()
t = []
c = -1
pre = "_"
for i in range(len(s)):
    if pre != s[i]:
        pre = s[i]
        c += 1
print(c)

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

Submission status: Accepted

Solution code:
N = input()

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

Submission status: Accepted

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

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())
ans=0
x=s[0]
for t in s:
  if x != t:
    ans+=1
    x=t
print(ans)

Submission status: Accepted

Solution code:
board = [c for c in input()]

# How many times the color of stone changed is the key.
ans = 0
color = board[0]

for stone in board:
    if stone != color:
        ans += 1
        color = stone

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    import collections
    deque = collections.deque()

    deque.append(s[0])
    for x in s[1:]:
        if deque[-1] != x:
            deque.append(x)

    return (len(deque)-1)


def main():
    print(solve())


if __name__ == '__main__':
    main()