Description
1 d 2…d n
1…d i-1 d j d j-1…d i d j+1 d j+2…d n.
Bobo would like to find
9+7).
Input
The input contains at most 30 sets. For each set:
5).
1 d 2…d n (0≤d i≤9).
Output
For each set, an integer denotes the result.
Sample Input
2
12
3
012
10
0123456789
Sample Output
#include<set>标签:1810,Reverse,int,res,CSU,const,mod,include,define From: https://blog.51cto.com/u_15870896/5838620
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int T, n;
LL L[N], l[N], r[N], R[N], a[N];
char s[N];
int main()
{
while (scanf("%d", &n) != EOF)
{
scanf("%s", s + 1);
rep(i, 1, n) a[i] = s[i] - '0';
l[0] = L[0] = R[0] = r[0] = 0;
rep(i, 1, n)
{
l[i] = (l[i - 1] + a[i]) % mod;
L[i] = (L[i - 1] + a[i] * i) % mod;
r[i] = (r[i - 1] + a[n - i + 1]) % mod;
R[i] = (R[i - 1] + a[n - i + 1] * i) % mod;
}
LL ans = 0, res;
rep(i, 1, n)
{
res = a[i] * (1LL * (i - 1)*i / 2 + 1LL * (n - i)*(n - i + 1) / 2) % mod;
res += a[i] * min(i, n - i + 1) % mod;
if (i - 1 >= n - i + 1)
{
res += L[n - i + 1] % mod;
res += (l[i - 1] - l[n - i + 1])*(n - i + 1) % mod;
}
else
{
res += L[i - 1] % mod;
}
if (n - i >= i)
{
res += R[i] % mod;
res += (r[n - i] - r[i])*i % mod;
}
else
{
res += R[n - i];
}
ans = (ans * 10 + res) % mod;
}
printf("%lld\n", ans);
}
return 0;
}