use std::collections::VecDeque; use std::io::{self, BufRead}; fn main() { // Read input let stdin = io::stdin(); let mut iterator = stdin.lock().lines(); let mut A = Vec::new(); for _ in 0..6 { A.push(iterator.next().unwrap().unwrap().parse::().unwrap()); } // Generate U array let U: Vec = (0..6).map(|i| 10i32.pow(i)).collect(); // Function to calculate the result fn calc(x: i32, y: i32, U: &Vec) -> i32 { let mut ANS = 0; for &i in U.iter() { ANS += ((x / i + y / i) % 10) * i; } ANS } // DP array let mut DP = vec![0; 1_000_000]; DP[0] = 1; let mut Q = VecDeque::new(); Q.push_back(0); // Process the queue while let Some(x) = Q.pop_front() { for &a in A.iter() { let to = calc(a, x, &U); if DP[to as usize] == 0 { DP[to as usize] = 1; Q.push_back(to); } } } // Sum the DP array let result: i32 = DP.iter().sum(); println!("{}", result); }