#![allow(unused_imports)] #![allow(unused_macros)] #![allow(dead_code)] #![allow(non_snake_case)] #![allow(non_camel_case_types)] use std::io::Read; use std::cmp; use std::collections::{HashSet, HashMap, VecDeque as Deque, BTreeSet}; use std::f64::consts::PI; type int = usize; type float = f64; const TAU: float = PI*2.; const M1: int = 1_000_000_007; const M9: int = 998_244_353; const INF: int = 9223372036854775807; fn yn(value: bool) {println!("{}", if value {"Yes"} else {"No"})} fn repeat(vector: Vec, n: int) -> Vec> where T: Clone{ let mut res = vec![]; for _ in 0..n { res.push(vec![]); for value in vector.iter() { res.last_mut().unwrap().push(value.clone()); } } res } fn flog(mut n: int, base: int) -> int { let mut res = 0; while n>=base { n /= base; res += 1; } res } fn pow(base: int, exp: int) -> int { powmod(base, exp, INF) } fn powmod(base: int, exp: int, modulo: int) -> int { if exp == 0 { return 1 % modulo } let mut res = powmod(base, exp/2, modulo).pow(2)%modulo; if exp%2==1 { res *= base; res %= modulo; } res } fn get_digits(mut value: int) -> Vec { let mut res = Vec::new(); while value > 0 { res.push(value%10); value /= 10; } res.into_iter().rev().collect() } fn get_bits(mut value: int ,size: int) -> Vec { let mut res = Vec::new(); for _ in 0..size { res.push(value%2); value >>= 1; } res } fn permutations(n: int, k: int) -> Vec> { let mut res = Vec::new(); let mut remain: BTreeSet<_> = (0..n).collect(); let mut now = Vec::new(); permutations_rec(&mut res, &mut now, &mut remain, k); res } fn permutations_rec(mut res: &mut Vec>, mut now: &mut Vec ,mut remain: &mut BTreeSet::, k: int) { if k == 0 { res.push(now.clone()); return; } let copy = remain.clone(); for i in copy { remain.remove(&i); now.push(i); permutations_rec(&mut res, &mut now, &mut remain, k-1); remain.insert(i); now.pop(); } } fn bsearch(x: int, v: &[int]) -> usize { let (mut ok, mut ng) = (0, v.len()); while ok+1 String { let mut res = String::new(); std::io::stdin().read_line(&mut res).unwrap(); res.trim().to_string() } macro_rules! debug {($($a:expr),* $(,)*) => {#[cfg(debug_assertions)] eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);};} fn mods(n: Vec) -> Vec { let len = 9*n.len()+1; let mut dp = repeat(vec![0].repeat(len), 2); dp[0][0] = 1; for &d in n.iter() { let mut update = repeat(vec![0].repeat(len), 2); for l in 0..2 { for c in 0..10 { if l==0 && c>d { continue; } for i in 0..len-c { update[l | (c = input_itr.next().unwrap().chars().map(|c| c.to_string().parse().unwrap()).collect(); let D: Vec = input_itr.next().unwrap().chars().map(|c| c.to_string().parse().unwrap()).collect(); let M: Vec = M.iter().map(|c| c.to_string().parse().unwrap()).collect(); let D: Vec = D.iter().map(|c| c.to_string().parse().unwrap()).collect(); let mut ans = 0; for (m, d) in mods(M).iter().zip(mods(D)).skip(1) { ans += m*d; ans %= 1000000009; } println!("{}", ans); }