#P10167. [DTCPC 2024] 小方学乘法

    ID: 11519 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2024洛谷月赛拉格朗日插值法

[DTCPC 2024] 小方学乘法

Background

Xiao Fang was in a math class and started learning multiplication, but he fell asleep in class.

Problem Description

He dreamed of a math formula that only contained digits and multiplication signs. Because the dream was blurry, he might have mistaken the multiplication sign for the letter xx.

Somehow he remembered the value of this xx, and he believed that letters can be treated as digits. So, after replacing all letters xx with digits, he computed the value of the expression.

Then he was caught sleeping by the coach.

Before being ganked, he wanted to recall the value he computed in the dream.

But Xiao Fang was too sleepy, so he decided to compute the value in all cases: that is, for each multiplication sign, replace it or do not replace it with the value represented by the letter xx, and sum the values over all possible cases.

However, Xiao Fang even forgot xx itself. He only remembers that it is within some range [L,R][L,R], so for each xx he needs to compute the sum described above, and then sum those results again.

Xiao Fang just learned multiplication and cannot handle very large numbers, so he wants you to output the answer mod109+7\bmod {10^9+7}.

Formal statement

You are given a string ss that contains only digits 191 \sim 9 and ?. It is guaranteed that there are no two adjacent ?, and the first and last characters of the string are not ?.

Now each ? can be replaced by xx or ×\times, where xx is a given string-concatenation variable.

For example, for 12x45, when x=33x=33, the replacement result is 123345.

Let the sum of the weights of the expression over all replacement schemes of ? when x=kx=k be f(k)f(k).

Compute i=LRf(i)mod109+7\sum_{i=L}^R{f(i)} \bmod {10^9 + 7}.

Input Format

The first line contains a string SS of length nn (1n20001 \le n \le 2000), representing the expression.

The second line contains two positive integers L,RL,R (1LR<10181 \le L \le R < 10^{18}).

Output Format

Output one positive integer, the answer modulo 109+710^9+7.

123?13?23
1 10
507086689

Hint

Translated by ChatGPT 5