const LOOP_COUNT: i32 = 1_000_000;
const EXPECTED_CHECKSUM: i32 = 3_875_007;

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 vec_i32_index_loop(limit: i32) -> i32 {
    let digits = vec![3, 1, 4, 1, 5, 9, 2, 6];
    let mut i = 0;
    let mut acc = 7;

    while i < limit {
        acc += digits[(i % digits.len() as i32) as usize];
        acc = if acc > 1_000_000_000 {
            acc - 1_000_000_000
        } else {
            acc
        };
        i += 1;
    }

    acc
}

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