const MOD: usize = 1e9 as usize + 7; fn main() { let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t = t.trim().chars().collect::>(); let mut d = String::new(); std::io::stdin().read_line(&mut d).ok(); let d: usize = d.trim().parse().unwrap(); if d == 0 { if t.iter().any(|&c| c != '0' && c != '?') { println!("0"); } else { println!("1"); } return; } let summary = t.iter().filter(|&&c| c != '?').map(|&c| c as usize - '0' as usize).sum::() % 9; let mut cnt = t.iter().filter(|&&c| c == '?').count(); let mut dp = vec![vec![0usize; 9]; cnt+1]; dp[0][summary] = 1; for i in 0..cnt { for j in 0..9 { if dp[i][j] == 0 { continue; } for k in 0..10 { let jidx = (j+k)%9; dp[i+1][jidx] += dp[i][j]; dp[i+1][jidx] %= MOD; } } } let d = d % 9; println!("{}", dp[cnt][d]); }