Problem:
Score : 400 points

Problem Statement

Given is a string S. Each character in S is either a digit (0, ..., 9) or ?.

Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.

Since the answer can be enormous, print the count modulo 10^9+7.

Constraints

S is a string consisting of digits (0, ..., 9) and ?.

1 \leq |S| \leq 10^5

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of integers satisfying the condition, modulo 10^9+7.

Sample Input 1

??2??5

Sample Output 1

768

For example, 482305, 002865, and 972665 satisfy the condition.

Sample Input 2

?44

Sample Output 2

1

Only 044 satisfies the condition.

Sample Input 3

7?4

Sample Output 3

0

We may not be able to produce an integer satisfying the condition.

Sample Input 4

?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???

Sample Output 4

153716888

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author caoash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DDigitsParade solver = new DDigitsParade();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDigitsParade {
        public void solve(int testNumber, FastScanner br, PrintWriter pw) {
            long MOD = (long) 1e9 + 7;
            char[] in = br.nextString().toCharArray();
            long[][] cnt = new long[in.length][13];
            int place = 0;
            for (int i = in.length - 1; i >= 0; i--) {
                if (place == 0) {
                    if (in[i] == '?') {
                        for (int dig = 0; dig <= 9; dig++) {
                            cnt[place][(((int) (powM(10, place, 13)) * dig)) % 13]++;
                        }
                    } else {
                        cnt[place][((int) (powM(10, place, 13) * (in[i] - '0'))) % 13]++;
                    }
                } else {
                    if (in[i] == '?') {
                        for (int j = 0; j < 13; j++) {
                            for (int dig = 0; dig <= 9; dig++) {
                                int modP = ((int) (powM(10, place, 13)) * dig);
                                cnt[place][(j + modP) % 13] += cnt[place - 1][j];
                                cnt[place][(j + (modP)) % 13] %= MOD;
                            }
                        }
                    } else {
                        for (int j = 0; j < 13; j++) {
                            int modP = ((int) (powM(10, place, 13)) * (in[i] - '0')) % 13;
                            cnt[place][(j + (modP)) % 13] += cnt[place - 1][j];
                            cnt[place][(j + (modP)) % 13] %= MOD;
                        }
                    }
                }
                ++place;
            }

            pw.println(cnt[in.length - 1][5] % MOD);
            pw.close();
        }

        public static long powM(int a, int b, int m) {
            a %= m;
            long res = 1;
            while (b > 0) {
                if ((b & 1) > 0)
                    res = (res * a) % m;
                a = a * a % m;
                b >>= 1;
            }
            return res;
        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastScanner.SpaceCharFilter filter;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}