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(); let contains_zero_only_pattern = !t.iter().any(|&c| c != '0' && c != '?'); if d == 0 { if contains_zero_only_pattern { println!("1"); } else { println!("0"); } return; } let summary = t.iter().filter(|&&c| c != '?').map(|&c| c as usize - '0' as usize).sum::() % 9; let 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; let result = (MOD + dp[cnt][d] - if d == 0 && contains_zero_only_pattern { 1 } else { 0 }) % MOD; println!("{}", result); }