import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { new Main().run(); } final long MOD=(long)1e9+7; long zero(char[] cs) { boolean ok=true; for (char c:cs) { ok&=c=='0'||c=='?'; } return ok?1:0; } void run() { FastScanner sc=new FastScanner(); char[] cs=sc.next().toCharArray(); int D=sc.nextInt(); if (D==0) { System.out.println(zero(cs)); return; } int sum=0; int pend=0; for (char c:cs) { if (c!='?') sum=(sum+(int)(c-'0'))%9; else ++pend; } long[][] dp=new long[pend+1][9]; dp[0][sum]=1; for (int i=0;i Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }