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 Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let s: Vec<usize> = s.chars().into_iter().map(|c| c.to_digit(10).unwrap_or(10) as usize).collect();
    let n = s.len() as usize;
    let mut dp: Vec<Vec<usize>> = vec![vec![0; 13]; n];
    let modular = 1000000007;
    if s[n-1] == 10 {
        for i in 0..10 {
            dp[n-1][i] = 1;
        }
    } else {
        dp[n-1][s[n-1] as usize] = 1;
    }
    for i in (0..n-1).rev() {
        if s[i] == 10 {
            for j in 0..13 {
                let mut sum = 0;
                for k in 0..10 {
                    let tmp = (k * mod_pow(10, (n-i-1) as i64, 13) % 13) as usize;
                    sum += dp[i+1][(j+13-tmp)%13];
                    sum %= modular;
                }
                dp[i][j] = sum;
            }
        } else {
            for j in 0..13 {
                let mut sum = 0;
                let tmp = (s[i] as i64 * mod_pow(10, (n-i-1) as i64, 13) % 13) as usize;
                sum += dp[i+1][(j+13-tmp)%13];
                sum %= modular;
                dp[i][j] = sum;
            }
        }
    }
    println!("{}", dp[0][5]);
}

fn mod_pow(x: i64, y: i64, z: i64) -> i64 {
    if y == 0 {
        1
    } else {
        let h = mod_pow(x, y / 2, z);
        let res = (h * h) % z;
        if y % 2 == 0 {
            res
        } else {
            (res * x) % z
        }
    }
}

*/

fn main() {
    let exe = "/tmp/bin3554517A";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";