use std::env::args; use std::fs::File; use std::io::BufRead; use std::io::BufReader; fn main() { let path = args().nth(1).unwrap(); let file = File::open(path).unwrap(); let mut x = 0; let mut y = 0; for line in BufReader::new(file).lines() { let l = line.unwrap(); let i = l.find(' ').unwrap(); let dir = &l[..i]; let k = &l[i+1..].parse::().unwrap(); match dir { "forward" => x += k, "down" => y += k, "up" => y -= k, _ => panic!("invalid direction"), } } print!("{}\n", x * y); }