CF1422C Bargain
Sometimes it is not easy to come to an agreement in a bargain. Right now Sasha and Vova can’t come to an agreement: Sasha names a price as high as possible, then Vova wants to remove as many digits from the price as possible. In more details, Sasha names some integer price , Vova removes a non-empty substring of (consecutive) digits from the price, the remaining digits close the gap, and the resulting integer is the price.
For example, is Sasha names , Vova can remove the substring , and the result is .
It is allowed for result to contain leading zeros. If Vova removes all digits, the price is considered to be .
Sasha wants to come up with some constraints so that Vova can’t just remove all digits, but he needs some arguments supporting the constraints. To start with, he wants to compute the sum of all possible resulting prices after Vova’s move.
Help Sasha to compute this sum. Since the answer can be very large, print it modulo .
Input
The first and only line contains a single integer .
Output
In the only line print the required sum modulo .
Examples
input
1 | 107 |
output
1 | 42 |
input
1 | 100500100500 |
output
1 | 428101984 |
Note
Consider the first example.
Vova can choose to remove . The results are . Their sum is .
Translation
给一个正整数 ,可以选择 上连续的位将之取出,于是 就成了新的数。求所有操作剩下的数的和。
Idea
如果去掉的连续位在 的头部或 的尾部,可 统计贡献。
若去掉的连续位在 的中部,首先预处理出数组 ,表示 从 位表示的数字。然后枚举去掉的连续位数的左右边界 和 ,那么 位的数字是被去掉的。首先枚举右边界 ,再枚举左边界 ,那么新的数字就是 ,其中 是 表示的数字。对于一个固定的右边界 ,枚举左边界时,首先计算去掉 位的数字,再计算去掉 位的数字,……,最后计算去掉 位的数字;因此 的取值是 ,产生的贡献是 。只需要处理 的前缀和,也可以在 时间内统计去掉中部连续位数的贡献。
Code
1 | /****************************************************************** |