观察发现每一位只需要维护后缀和
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 5e5 + 10;
int n;
LL sum[N];
char s[N];
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
vector<int> c;
LL tot = 0;
for (int i = 1; i <= n; i ++ ) sum[i] = sum[i - 1] + s[i] - '0';
reverse(sum + 1, sum + 1 + n);
for (int i = 1; i <= n; i ++ ) {
tot += sum[i];
c.push_back(tot % 10);
tot /= 10;
}
while (tot) {
c.push_back(tot % 10);
tot /= 10;
}
reverse(c.begin(), c.end());
for (auto x : c)
printf("%d", x);
printf("\n");
return 0;
}