use std::collections::HashSet; use std::io::{self, BufRead}; fn main() { // Part 1 let mut part1 = 0; let cards: Vec = io::stdin() .lock() .lines() .map(|line| { let line = line.unwrap(); let (_, card) = line.split_once(": ").unwrap(); let (winning, owned) = card.split_once(" | ").unwrap(); let winning: HashSet = winning .split_whitespace() .flat_map(str::parse) .collect(); let owned: HashSet = owned .split_whitespace() .flat_map(str::parse) .collect(); let count = winning.intersection(&owned).count(); part1 += 1 << (count - 1); count }) .collect(); // Part 2 let mut dp = vec![1; cards.len()]; let part2: i32 = (0..cards.len()) .map(|i| { dp[i] += dp[i - cards[cards.len() - i - 1]..i].iter().sum::(); dp[i] }) .sum(); println!("{} {}", part1, part2); }