use std::io;
use std::io::Read;

fn main() {
    let mut stdin: io::Stdin = io::stdin();

    let mut result: u32 = 0;
    let mut buf: String = String::new();
    stdin.read_to_string(&mut buf).unwrap();
    let lines: Vec<&str> = buf.split("\n").collect();
    let mut lg: Vec<(&str, Vec<&str>)> = vec![];

    // for line in lines { // part 1
    //     lg.push((&line[..line.len() / 2], vec![&line[line.len() / 2..]]))
    // }
    for i in 0..(lines.len() / 3) { // part 2
        lg.push((lines[i * 3], vec![lines[i * 3 + 1], lines[i * 3 + 2]]));
    }

    for (a, rest) in lg {
        match in_common(a, rest) {
            Some(x) => result += priority(x),
            None => {}
        }
    }

    println!("done? {}", result);
}

fn in_common(a: &str, rest: Vec<&str>) -> Option<char> {
    for i in a.chars() {
        let mut yes = true;
        for s in &rest {
            if let None = s.find(i) { // goofy ahh formatting 
                yes = false; break; 
            }
        }
        if yes { return Some(i); }
    }
    None
}

fn priority(a: char) -> u32 {
    let mut b: [u8; 1] = [0];
    a.encode_utf8(&mut b);
    return (b[0] - if b[0] > 0x60 { 0x60 } else { 0x40 - 26 }) as u32;
}