use std::io::*; const MOD: usize = 1_000_000_007; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let s: Vec = itr.next().unwrap().chars().collect(); let n = s.len(); let d: usize = itr.next().unwrap().parse().unwrap(); let mut dp = vec![vec![0; 10]; n + 1]; dp[0][0] = 1; for i in 0..n { for j in 0..10 { // 桁和がjの場合から遷移 if s[i] == '?' { for k in 0..10 { dp[i + 1][(j * 10 + k) % 9] += dp[i][j]; dp[i + 1][(j * 10 + k) % 9] %= MOD; } } else { let x = (s[i] as u8 - '0' as u8) as usize; dp[i + 1][(j * 10 + x) % 9] += dp[i][j]; dp[i + 1][(j * 10 + x) % 9] %= MOD; } } } println!("{}", dp[n][d % 9]); }