#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars
    }
    // let mut ch = s[0];
    // for i in 1..s.len() {
    //     if ch != s[i] {
    //         ch = s[i];
    //     }else{

    //         ch = s[i];
    //     }
    // }
    let mut rle:Vec<(char, u64)> = vec![];
    let mut ch:char = 'a';
    let mut len = 0;
    let mut ind = vec![];
    for i in 0..s.len() {
        if ch == 'R' && s[i]=='L' {
            ind.push(i);
        }
        if i==0 {
            ch = s[i];
            len = 1;
            continue;
        }
        if ch==s[i] {
            len+=1;
        }
        if ch!=s[i] {
            rle.push((ch, len));
            ch = s[i];
            len = 1;
        }
        if i==s.len()-1 {
            rle.push((ch, len));
        }
    }
    // println!("{:?}", rle);
    let mut flag = false;
    let mut ans = 0;
    for i in 0..rle.len() {
        let k = if flag {
            flag = false;
            rle[i].1- 1
        }else{
            rle[i].1
        };
        if k%3 == 0 {
            ans+=((rle[i].1)/3) * 2;
        }
        if k%3 == 1 {
            ans+=((rle[i].1)/3) * 2 + 1;
        }
        if k%3 == 2{
            flag = true;
            if i==rle.len()-1 {
                ans+=(rle[i].1/3) * 2 + 1;
            }else{
                ans+=(rle[i].1/3) * 2 + 2;
            }
        }
    }
    println!("{}", ans);
}