use std::cmp::*; 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(); // ketawa zero is zenbu zero let mut zero = true; if d == 0 { for i in 0..n { if s[i] != '?' && s[i] != '0' { zero = false; break; } } println!("{}", zero as u32); return; } let mut dp = vec![vec![0; 10]; n + 1]; dp[0][0] = 1; for i in 0..n { for j in 0..10 { 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; } } } // ketawa 0にできる場合 WA if zero && d == 9 { dp[n][0] -= 1; } println!("{}", dp[n][d % 9]); }