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

Solution in Rust (1.15.1) (judge verdict: Time Limit Exceeded)

use std::io;

macro_rules! parse_input {
   ($x:expr, $t:ident) => ($x.trim().parse::<$t>().unwrap())
}

macro_rules! parse_inputs {
   ($x:expr, $t:ident) => (
       $x.trim()
       .split_whitespace()
       .map(|s| s.parse::<$t>().unwrap())
       .collect::<Vec<$t>>()
   )
}

macro_rules! print_err {
   ($($arg:tt)*) => (
       {
           use std::io::Write;
           writeln!(&mut ::std::io::stderr(), $($arg)*).ok();
       }
   )
}

fn check(ss: &Vec<char>) -> bool {
    let c = ss[0];
    for s in &ss[1..] {
        if c != *s {
            return false;
        }
    }
    return true;
}
fn main() {
    let mut input_line = String::new();
    io::stdin().read_line(&mut input_line).unwrap();
    let ss = input_line.trim().chars().collect::<Vec<char>>();
    let sslen = ss.len();

    if check(&ss) {
        println!("0", );
        return;
    }

    let mut ans: u64 = u64::max_value();

    for i in 0..2 {
        let mut flag = i;
        let mut count = 0;
        let mut ssclone = ss.clone();

        loop {
            // println!("flag:{} count:{}", flag, count);
            // print!("ssclone before:");
            // for c in &ssclone {
            //     print!("{}", c);
            // }
            // println!("", );

            let rev_color = if flag == 0 { ssclone[0] } else { ssclone[sslen - 1] };
            // println!("rev_color:{}", rev_color);

            if flag == 0 {
                // println!("flag == 0", );
                for i in 0..sslen {
                    if ssclone[i] == rev_color {
                        ssclone[i] = if rev_color == 'W' { 'B' } else { 'W' };
                    } else {
                        break;
                    }
                }
                flag = 1;
                count += 1;
            }
             else if flag == 1 {
                //  println!("flag == 1", );
                for i in (0..sslen).rev() {
                    if ssclone[i] == rev_color {
                        ssclone[i] = if rev_color == 'W' { 'B' } else { 'W' };
                    } else {
                        break;
                    }
                }
                flag = 1;
                count += 1;
            }
            if check(&ssclone) {
                // println!("break! conut:{}", count);
                break;
            }
        }
        if count < ans {
            ans = count;
            // println!("ans:{}", ans);
        }
    }

    println!("{}", ans);


}