const LOOP_COUNT: i32 = 1_000_000;
const EXPECTED_CHECKSUM: i32 = 4_600_001;

fn configured_loop_count() -> i32 {
    let mut input = String::new();
    if std::io::stdin().read_line(&mut input).is_err() {
        return LOOP_COUNT;
    }

    input
        .trim()
        .parse::<i32>()
        .ok()
        .filter(|value| *value > 0)
        .unwrap_or(LOOP_COUNT)
}

fn configured_target() -> String {
    std::env::args()
        .nth(1)
        .unwrap_or_else(|| "omega".to_string())
}

fn vec_string_eq_loop(limit: i32, target: &str) -> i32 {
    let words = vec!["alpha", "omega", "delta", "omega", "sigma"];
    let mut i = 0;
    let mut acc = 1;

    while i < limit {
        let current = words[(i % words.len() as i32) as usize];
        acc = if current == target { acc + 7 } else { acc + 3 };
        acc = if acc > 1_000_000_000 {
            acc - 1_000_000_000
        } else {
            acc
        };
        i += 1;
    }

    acc
}

fn main() {
    let target = configured_target();
    let result = vec_string_eq_loop(configured_loop_count(), &target);
    println!("{}", result);
    std::process::exit(if result == EXPECTED_CHECKSUM { 0 } else { 1 });
}
