# 【Codeforces 1422 C】Bargain，dp方案书，组合分类计算贡献

#### problem

C. Bargain
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 n, 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 1213121, Vova can remove the substring 1312, and the result is 121.

It is allowed for result to contain leading zeros. If Vova removes all digits, the price is considered to be 0.

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 109+7.

Input
The first and only line contains a single integer n (1≤n<10105).

Output
In the only line print the required sum modulo 109+7.

Examples
inputCopy
107
outputCopy
42
inputCopy
100500100500
outputCopy
428101984
Note
Consider the first example.

Vova can choose to remove 1, 0, 7, 10, 07, or 107. The results are 07, 17, 10, 7, 1, 0. Their sum is 42.

Sasha希望提出一些约束，以便Vova不能只删除所有数字，但他需要一些支持约束的参数。首先，他想计算Vova搬家后所有可能产生的价格之和。

inputCopy
107
outputCopy
42
inputCopy
100500100500
outputCopy
428101984

Vova可以选择删除1、0、7、10、07或107。结果为07、17、10、7、1、0。它们的总和为42。

#### solution

/*

+ 给出一个数字，选出连续一段去掉，剩下部分合起来。
+ 求出所有选择方案剩下数字的和。

+ 枚举每个数位的贡献。对于当前位x，如果删后面的，分删1-i位i种情况，贡献为x*10^i。如果删除前面的，数值直接为x，所以贡献为前面的删除方案数*x。
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const int mod = 1e9+7;
LL pows[maxn], f[maxn];
int main(){
string s;  cin>>s;  s="0"+s;
LL n=s.size()-1;
pows[0] = 1;
for(LL i = 1; i <= n; i++)
pows[i] = pows[i-1]*10%mod;
for(LL i = 1; i <= n; i++)//前面的删除方案数
f[i] = f[i-1]+i*pows[i-1]%mod;
LL ans = 0;
for(LL i = 1; i <= n; i++){
LL num = s[i]-'0';
ans = (ans+num*f[n-i]%mod)%mod;
if(i != 1){
ans += i*(i-1)/2%mod*pows[n-i]%mod*num%mod;
ans %= mod;
}
}
cout<<ans<<"\n";
return 0;
}



10-07 1704

09-26 1267
08-23 1230
12-25 1369
08-10 1345
04-18 1798
08-12 1483
11-22 1316
11-03 1378
08-20 1373
10-29 1366
05-11 2319
08-20 1338