use std::io::{self, Read};

fn main() {
    let mut f = io::stdin();
    let mut buf: String = String::new();
    f.read_to_string(&mut buf).unwrap();
    let mut total: u32 = 0;
    for l in buf.lines() {
        let (c1, c2) = { let mut bytes = l.bytes(); (bytes.nth(0).unwrap(), bytes.nth(1).unwrap()) };
        let their_choice = c1 - 0x41;
        // let my_choice = c2 - 0x58; // part 1
        // let diff = (my_choice + 4 - their_choice) % 3; // +3 so we can avoid underflow
        let diff: u8 = c2 - 0x58; // part 2
        let my_choice = (their_choice + diff + 2) % 3;
        total += (my_choice + 1 + diff * 3) as u32;
    }
    println!("{}", total);
}