Samantha and Sam are playing a numbers game.  Given a number as a string, no leading zeros, determine the sum of all integer values of substrings of the string.   

Given an integer as a string, sum all of its substrings cast as integers.  As the number may become large, return the value modulo $10^9+7$.  

Example 

$n=\text{'}42\text{'}$  

Here $n$ is a string that has $3$ integer substrings: $\begin{array}{c}A\end{array}$, $2$, and $\textbf{42}$.  Their sum is $48$, and $48\ \text{modulo}\ (10^9+7)=48$.

Function Description

Complete the substrings function in the editor below.   

substrings has the following parameter(s):  

string n: the string representation of an integer   

Returns   

int: the sum of the integer values of all substrings in $n$, modulo $10^9+7$

Input Format

A single line containing an integer as a string, without leading zeros.  

Constraints

$1\leq ncastas an integer\leq2\times10^5$

Sample Input 0
16

Sample Output 0
23

Explanation 0

The substrings of 16 are 16, 1 and 6 which sum to 23.

Sample Input 1
123

Sample Output 1
164

Explanation 1

The substrings of 123 are 1, 2, 3, 12, 23, 123 which sum to 164.

Difficulty: MEDIUM
Tags: Dynamic programming
Skill types: Dynamic programming

Starter code:

Solutions:
import operator
MOD = 1000000007
s = input()
n = len(s)
a = []
p10 = 0
for i in range(n, 0, -1):
	p10 = (p10 * 10 + 1) % MOD
	a.append(p10 * i % MOD)
b = [ord(c) - ord('0') for c in s]
print(sum(map(operator.mul, reversed(a), b)) % MOD)


M = 10 ** 9 + 7
N = input().strip()
(S, B, answer) = (0, 1, 0)
for i in range(len(N) - 1, -1, -1):
	answer = (answer + int(N[i]) * B * (i + 1)) % M
	S -= int(N[i])
	B = (B * 10 + 1) % M
print(answer)


def ext_gcd(aneek, sayantan):
	ash = aneek // sayantan
	champa = aneek - sayantan * ash
	shreejit = [1, 0]
	while champa != 0:
		aneek = sayantan
		sayantan = champa
		shreejit.append(shreejit[0] - ash * shreejit[1])
		shreejit = shreejit[1:]
		ash = aneek // sayantan
		champa = aneek - sayantan * ash
	return shreejit[1]

def inv_mod(xavi, prime):
	barca = ext_gcd(xavi, prime)
	if barca < 0:
		barca += prime
	return barca

def sum_all(s, p):
	n = len(s)
	z = 1
	ans = 0
	q = inv_mod(9, p)
	for i in range(n):
		if s[0] == '0':
			continue
		else:
			k = n - i
			m = (pow(10, k, p) - 1) * z * int(s[i]) % p
			m = m * q % p
			ans = (ans + m) % p
			z += 1
	return ans
s = input().strip()
p = int(1000000000.0 + 7)
print(sum_all(s, p))


inpt = input()
length = len(inpt)
sum = 0
for i in range(length):
	sum += int(inpt[i]) * (i + 1) * int('1' * (length - i))
print(sum % (10 ** 9 + 7))


import sys
MOD = 1000000007
N = list(map(int, list(sys.stdin.readline().strip())))
total = 0
k = 1
for (i, digit) in enumerate(reversed(N)):
	total += k * digit * (len(N) - i) % MOD
	k = (10 * k + 1) % MOD
print(total % MOD)


import sys
N = sys.stdin.readline().strip()
S = [0] * len(N)
S[0] = int(N[0])
for i in range(1, len(N)):
	S[i] = ((i + 1) * int(N[i]) + 10 * S[i - 1]) % 1000000007
print(sum(S) % 1000000007)


N = input()
s = 1
res = 0
cnt = len(N)
for i in reversed(N):
	res = (res + cnt * s * int(i)) % 1000000007
	cnt = cnt - 1
	s = (s * 10 + 1) % 1000000007
print(res)


S = input()
L = [1]
t = 1
N = len(S)
for i in range(1, N):
	t *= 10
	t %= 1000000007
	L.append((L[i - 1] + t) % 1000000007)
ans = 0
for i in range(N):
	ans += (i + 1) * L[N - 1 - i] * int(S[i]) % 1000000007
	ans %= 1000000007
print(ans)


MAX_SIZE = 10 ** 9 + 7
num = input()
n = len(num)
dp = int(num[-1]) * n
mult = 1
sum1 = 1
for i in range(n - 2, -1, -1):
	mult = 10 * mult % MAX_SIZE
	sum1 += mult
	dp = (dp + sum1 * int(num[i]) * (i + 1)) % MAX_SIZE
print(dp)


n = input()
dp = [int(n[0])]
ans = dp[0]
for i in range(1, len(n)):
	dp.append((int(n[i]) * (i + 1) + 10 * dp[i - 1]) % (10 ** 9 + 7))
	ans = (ans + dp[i]) % (10 ** 9 + 7)
print(ans % (10 ** 9 + 7))


N = input()
s_minus_one = s = int(N[0])
for i in range(len(N) - 1):
	s_minus_one = ((i + 2) * int(N[i + 1]) + 10 * s_minus_one) % 1000000007
	s = (s + s_minus_one) % 1000000007
print(s)


m = 10 ** 9 + 7
s = input()
(last, total) = (0, 0)
for (i, c) in enumerate(s):
	d = int(c)
	last = (last * 10 + (i + 1) * d) % m
	total = (total + last) % m
print(total)


numStr = input()
length = len(numStr)
sum = 0
prevSum = 0
modInt = 1000000007
for i in range(0, length):
	prevSum = prevSum * 10 + (i + 1) * int(numStr[i])
	prevSum %= modInt
	sum = (sum + prevSum) % modInt
print(sum)


st = input()
l = len(st)
dp = [1]
p10 = 1
MOD = 1000000007
for i in range(1, l):
	p10 *= 10
	p10 %= MOD
	dp.append((dp[i - 1] + p10) % MOD)
ans = 0
for i in range(l):
	ans += (i + 1) * dp[l - 1 - i] * (ord(st[i]) - ord('0'))
	ans %= MOD
print(str(ans))


s = input()
n = len(s)
dp = list(range(n))
dp[0] = int(s[0])
sumN = dp[0]
for i in range(1, n):
	dp[i] = (10 * dp[i - 1] + (i + 1) * int(s[i])) % 1000000007
	sumN += dp[i]
	sumN %= 1000000007
print(sumN)


s = input()
len1 = len(s)
mul_ten = 1
sum1 = 1
total_sum = len1 * int(s[len1 - 1])
for i in range(len1 - 2, -1, -1):
	mul_ten = mul_ten * 10 % 1000000007
	sum1 = sum1 + mul_ten
	total_sum = (total_sum + sum1 * (i + 1) * int(s[i])) % 1000000007
print(total_sum % 1000000007)


num = input()
size = len(num)
dp = [0] * size
dp[0] = int(num[0])
ans = dp[0]
for i in range(1, size):
	dp[i] = (dp[i - 1] * 10 + int(num[i]) * (i + 1)) % 1000000007
	ans = (ans + dp[i]) % 1000000007
print(ans)


def subsum(n):
	s = [0] * len(n)
	s[0] = int(n[0])
	for i in range(1, len(n)):
		s[i] = (10 * s[i - 1] + (i + 1) * int(n[i])) % (10 ** 9 + 7)
	return sum(s) % (10 ** 9 + 7)
n = input()
print(subsum(n))


MOD = 10 ** 9 + 7
digits = [int(x) for x in list(input().rstrip())]
dp = [0 for _ in range(len(digits) + 1)]
for i in range(len(digits)):
	dp[i + 1] = (dp[i] * 10 + (i + 1) * digits[i]) % MOD
print(sum(dp) % MOD)


def main(nstr):
	rmult = 1
	total = 0
	MOD = 10 ** 9 + 7
	for (lmult, digit) in reversed(list(enumerate(nstr))):
		total += (lmult + 1) * int(digit) * rmult % MOD
		rmult = (10 * rmult + 1) % MOD
	return total % MOD
print(main(input()))


import sys
MOD = 1000000007
N = list(map(int, list(sys.stdin.readline().strip())))
total = 0
k = 1
for (i, digit) in enumerate(reversed(N)):
	total += k * digit * (len(N) - i) % MOD
	k = (10 * k + 1) % MOD
print(total % MOD)


import sys
MOD = 1000000007
N = list(map(int, list(sys.stdin.readline().strip())))
total = 0
k = 1
for (i, digit) in enumerate(reversed(N)):
	total += k * digit * (len(N) - i) % MOD
	k = (10 * k + 1) % MOD
print(total % MOD)


S = input()
N = len(S)
mod = 10 ** 9 + 7
ans = 0
c = 0
dp = [0] * N
for i in range(N):
	c = (pow(10, i, mod) + c) % mod
	dp[i] = c
for i in range(N - 1, -1, -1):
	ans = (int(S[i]) * dp[N - 1 - i] * (i + 1) + ans) % mod
print(ans)


M = 10 ** 9 + 7
lis = list(map(int, input()))
n = len(lis)
T = [0, 1]
for i in range(n):
	T.append((T[-1] * 10 + 1) % M)
res = 0
for (i, x) in enumerate(lis):
	res = (res + (i + 1) * T[n - i] * x) % M
print(res)


def sub_string(n):
	MOD_NUM = 10 ** 9 + 7
	res = 0
	board = [int(n[0])]
	for (i, item) in enumerate(n[1:]):
		num = int(item)
		map_num = board[-1] * 10 % MOD_NUM + (i + 2) * num % MOD_NUM
		board.append(map_num % MOD_NUM)
	for i in board:
		res = (res % MOD_NUM + i % MOD_NUM) % MOD_NUM
	return res
print(sub_string(input()))


def sumsubstrings(st):
	mult = 1
	sum = 0
	mo = 10 ** 9 + 7
	for i in range(len(st), 0, -1):
		sum = (sum + int(st[i - 1]) * mult * i) % mo
		mult = (mult * 10 + 1) % mo
	return sum
st = input()
print(sumsubstrings(st))


MOD = 1000000007
arr = list(map(int, list(input())))
count = [arr[0]]
pow2 = 1
for i in range(1, len(arr)):
	count.append((count[i - 1] * 10 + arr[i] * (i + 1)) % MOD)
sum = 0
for i in range(len(count)):
	sum += count[i]
print(sum % MOD)


M = 1000000007
digits = [int(x) for x in input()]
s = sd = digits.pop(0)
c = 2
for d in digits:
	sd = (sd * 10 + c * d) % M
	s = (s + sd) % M
	c += 1
print(s)


def main():
	S = input()
	L = len(S)
	D = [int(c) for c in reversed(S)]
	for i in range(L - 2, -1, -1):
		D[i] = D[i + 1] + D[i] * (L - i)
		D[i] %= 1000000007
	P = 1
	T = 0
	for i in range(L):
		T += D[i] * P
		T %= 1000000007
		P *= 10
		P %= 1000000007
	print(T)
main()


n = input()
ans = 0
last = 0
p = int(1000000000.0 + 7)
for i in range(len(n)):
	last *= 10
	last += int(n[i]) * (i + 1)
	last %= p
	ans += last
	ans %= p
print(ans)


import sys
INT = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

def mod(x):
	return x % 1000000007

def solve(S):
	answer = INT[S.__next__()]
	prefix_sum = answer
	x = 11
	for char in S:
		prefix_sum = INT[char] * x + prefix_sum
		answer += prefix_sum
		x = 10 * mod(x) + 1
	return answer
S = sys.stdin.readline().strip()
print(mod(solve(reversed(S))))


string = input()
modulo = 10 ** 9 + 7
array = []
array1 = []
length = len(string)
string = [int(x) for x in string]
f = 1
res = 0
for i in range(len(string) - 1, -1, -1):
	res = (res + string[i] * (i + 1) * f) % modulo
	f = (f * 10 + 1) % modulo
print(res)


def get_answer(digits):
	M = len(digits)
	answer = 0
	X = 10 ** 9 + 7
	const = [1] * M
	ten_pow = 1
	for i in range(1, M):
		ten_pow = ten_pow * 10 % X
		const[i] = (const[i - 1] + ten_pow) % X
	for i in range(M - 1, -1, -1):
		answer = (answer + digits[i] * (i + 1) * const[M - 1 - i]) % X
	print(answer % X)
N = input()
digits = []
for i in range(0, len(N)):
	digits.append(int(N[i]))
get_answer(digits)


s = input()
len1 = len(s)
mul_ten = 1
sum1 = 1
total_sum = len1 * int(s[len1 - 1])
for i in range(len1 - 2, -1, -1):
	mul_ten = mul_ten * 10 % 1000000007
	sum1 = sum1 + mul_ten
	total_sum = (total_sum + sum1 * (i + 1) * int(s[i])) % 1000000007
print(total_sum % 1000000007)


x = input()
mod = pow(10, 9) + 7
total = 0
t = 1
c = 1
for i in range(len(x)):
	total = (total + (ord(x[len(x) - i - 1]) - ord('0')) * t * (len(x) - i)) % mod
	c = c * 10 % mod
	t = (t + c) % mod
print(total)


s = input()
n = len(s)
f = [0] * (n + 1)
c = [0] * (n + 1)
MOD = 10 ** 9 + 7
for i in range(1, n + 1):
	d = int(s[i - 1])
	c[i] = (c[i - 1] * 10 + i * d) % MOD
r = 0
for z in c:
	r = (r + z) % MOD
print(r)


mod = 10 ** 9 + 7

def sol(S):
	n = len(S)
	ones = 1
	s = 0
	for idx in range(n - 1, -1, -1):
		s += (idx + 1) * ones * int(S[idx]) % mod
		ones = (ones * 10 + 1) % mod
	return s % (10 ** 9 + 7)
print(sol(input()))


import sys
from functools import *
import time
start = time.time()
x = input()
M = [0] * len(x)
M[0] = int(x[0])
total = 0
for i in range(1, len(x)):
	temp = int(x[i])
	M[i] = (M[i - 1] * 10 + (i + 1) * temp) % (pow(10, 9) + 7)
total += reduce(lambda x, y: x + y, M)
print(total % (pow(10, 9) + 7))


def main():
	s = input()
	prev_res = 0
	cur_res = 0
	res = 0
	n = len(s)
	for i in range(0, n):
		cur_res = ((i + 1) * int(s[i]) + 10 * prev_res) % 1000000007
		prev_res = cur_res
		res = (res + cur_res) % 1000000007
	print(res)
main()


def main():
	Mod = 10 ** 9 + 7
	s = [0] + list(map(int, list(input())))
	n = len(s)
	ans = 0
	now = 0
	for i in range(1, n):
		now = (now * 10 + s[i] * i) % Mod
		ans = ans + now
		if ans >= Mod:
			ans -= Mod
	print(ans)
main()


import math
n = input().strip()
previous = [int(n[0]), int(n[0])]
for i in range(1, len(str(n))):
	previous[1] = (previous[1] * 10 + int(n[i]) * (i + 1)) % (10 ** 9 + 7)
	previous[0] = (previous[0] + previous[1]) % (10 ** 9 + 7)
print(previous[0])


MOD = 10 ** 9 + 7
A = input().strip()
A = list(map(int, list(str(A))))
n = len(A)
G = [0 for t in range(n + 1)]
G[0] = 0
G[1] = A[0]
for t in range(2, n + 1):
	G[t] = (11 * G[t - 1] - 10 * G[t - 2] + t * A[t - 1]) % MOD
print(G[n])


string = input().strip()
tenPowKModuloP = [1] * (len(string) + 1)
for i in range(1, len(string) + 1, 1):
	tenPowKModuloP[i] = tenPowKModuloP[i - 1] * 10 % (10 ** 9 + 7)
k1sModuloP = [1] * (len(string) + 1)
for i in range(2, len(string) + 1, 1):
	k1sModuloP[i] = (k1sModuloP[i - 1] + tenPowKModuloP[i - 1]) % (10 ** 9 + 7)
n_of_prev_nonzero_digits = 0
i = 0
ret = 0
for ch in string:
	digit = int(ch)
	if True or digit != 0:
		n_of_prev_nonzero_digits += 1
	ret = (ret + n_of_prev_nonzero_digits * digit * k1sModuloP[len(string) - i]) % (10 ** 9 + 7)
	i += 1
print(ret)


mod = 10 ** 9 + 7
s = input()
n = len(s)
pos = 1
total = 0
for k in range(n, 0, -1):
	total = (total + int(s[k - 1]) * k * pos % mod) % mod
	pos = (pos * 10 + 1) % mod
print(total)


def grand_total(string):
	(total, mult) = (0, 1)
	for i in range(len(string), 0, -1):
		total += int(string[i - 1]) * mult * i
		mult = (mult * 10 + 1) % (10 ** 9 + 7)
	return total
print(grand_total(input()) % (10 ** 9 + 7))


def main():
	str = input()
	dp = 1
	n = len(str)
	ans = int(str[n - 1])
	a = int(str[n - 1])
	dp = dp * 10 + 1
	if n > 1:
		b = a + dp * int(str[n - 2])
		ans = ans + b
	for i in range(2, n):
		dp = dp * 10 + 1
		dp = dp % 1000000007
		b = b + dp * int(str[n - i - 1])
		b = b % 1000000007
		ans = ans + b
		ans = ans % 1000000007
	print(ans)
main()


digits = input()[::-1]
N = len(digits)
M = 10 ** 9 + 7
ones = 0
T = 0
for i in range(N):
	ones += pow(10, i, M)
	ones %= M
	T += (N - i) * ones * int(digits[i])
	T %= M
print(T)


n = input()
b = str(n)
c = []
length = len(n)
for digit in b:
	c.append(int(digit))
res = 0
f = 1
for i in range(length - 1, -1, -1):
	res = (res + c[i] * f * (i + 1)) % 1000000007
	f = (f * 10 + 1) % 1000000007
print(res)


s = input()
n = len(s)
ans = [-1 for x in range(n)]
sm = [-1 for x in range(n)]
for i in range(n):
	ans[i] = int(s[i])
sm[0] = ans[0]
p = 0
for i in range(1, n):
	p += ans[i - 1]
	p = (p * 10 + ans[i] * i) % 1000000007
	sm[i] = sm[i - 1] + ans[i] + p
	sm[i] %= 1000000007
print(sm[n - 1])


num = input()
l = len(num)
prev = 0
finans = 0
for i in range(l):
	ans = prev * 10
	ans += int(num[i]) * (i + 1) % 1000000007
	ans = ans % 1000000007
	prev = ans
	finans += ans
print(finans % 1000000007)


s = input()
res = 0
j = 1
mod = 10 ** 9 + 7
for i in reversed(range(len(s))):
	res = (res + int(s[i]) * j * (i + 1)) % mod
	j = (j * 10 + 1) % mod
print(res)


n = input()
l = len(n)
a = [0] * l
for i in range(l):
	a[i] = int(n[i])
ans = 0
one = 1
for i in range(l - 1, -1, -1):
	ans = (ans + a[i] * one * (i + 1)) % (10 ** 9 + 7)
	one = (one * 10 + 1) % (10 ** 9 + 7)
print(ans)


from sys import stdin
n = stdin.readline().rstrip()
(add, counter, multi, mod) = (0, len(n), 1, 1000000000 + 7)
for i in n[::-1]:
	add = add % mod + multi * int(i) * counter % mod
	(multi, counter) = ((multi * 10 + 1) % mod, (counter - 1) % mod)
print(add % mod)


mod = 1000000007
st = input()
length = len(st)
dp = [0 for i in range(length + 1)]
dp[1] = int(st[0])
for i in range(2, length + 1):
	dp[i] = ((dp[i - 1] - dp[i - 2]) * 10 + i * int(st[i - 1]) + dp[i - 1]) % mod
print(dp[length])


M = 10 ** 9 + 7
s = 0
t = 0
for (i, c) in enumerate(map(int, input())):
	s = (10 * s + c * (i + 1)) % M
	t += s
print(t % M)


iArr = list(map(int, list(input())))
digit = len(iArr)
sArr = [0] * digit
sArr[0] = iArr[0]
for i in range(1, digit):
	sArr[i] = (sArr[i - 1] + iArr[i] * (i + 1)) % 1000000007
totalSum = 0
curDigit = 1
for i in range(digit - 1, -1, -1):
	totalSum += curDigit * sArr[i]
	totalSum = totalSum % 1000000007
	curDigit = curDigit * 10 % 1000000007
print(totalSum % 1000000007)


a = input()
sum = 0
z = 0
for i in range(len(a)):
	if i == 0:
		z = int(a[i])
		sum += z
		continue
	z = z * 10 + int(a[i]) * (i + 1)
	sum += z
print(sum % 1000000007)


import time
N = input()
candies = 0
param = 1
for i in range(len(N), 0, -1):
	candies = (candies + i * param * int(N[i - 1])) % 1000000007
	param = (10 * param + 1) % 1000000007
print(candies)


s = input()
n = len(s)
dp = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	dp[i] = (dp[i - 1] * 10 + int(s[i - 1]) * i) % (10 ** 9 + 7)
print(sum(dp) % (10 ** 9 + 7))


import sys
import math

def sam(n):
	length = len(n)
	result = 0
	mod = math.pow(10, 9) + 7
	input_list = list(n)
	new_list = [int(i) for i in input_list]
	result = 0
	significance = 1
	for i in range(length, 0, -1):
		result = (result + new_list[i - 1] * significance * i) % mod
		significance = (significance * 10 + 1) % mod
	return int(result)
n = input().strip()
print(sam(n))


str = input()
modulus = 10 ** 9 + 7
n = len(str)
sum = 0
place_value_multiplier = 1
for i in range(n - 1, -1, -1):
	sum += int(str[i]) * (i + 1) * place_value_multiplier
	sum = sum % modulus
	place_value_multiplier = place_value_multiplier * 10 + 1
	place_value_multiplier = place_value_multiplier % modulus
print(sum)


import sys
import fileinput
line = input()
ans = 0
times = len(line)
tot_len = times
mul = 1
for i in range(tot_len - 1, -1, -1):
	ans = ans + times * int(line[i]) * mul
	mul = (mul * 10 + 1) % 1000000007
	times -= 1
ans %= 1000000007
print(ans)


M = 10 ** 9 + 7
x = input()
prev = ans = 0
for (i, x) in enumerate(x):
	tmp = (i + 1) * int(x) + prev * 10
	tmp %= M
	ans = (ans + tmp) % M
	prev = tmp
print(ans)


import sys
MOD = 1000000007
N = list(map(int, list(sys.stdin.readline().strip())))
total = 0
k = 1
for (i, digit) in enumerate(reversed(N)):
	total += k * digit * (len(N) - i) % MOD
	k = (10 * k + 1) % MOD
print(total % MOD)


sample = input()
m = 1000000007
n = len(sample)
base = 1
answer = 0
for ch in reversed(sample):
	answer += base % m * int(ch) * n % m
	base = (base * 10 + 1) % m
	n -= 1
print(answer % m)


k = input()
n = len(k)
dp = [0] * (1 + n)
total = 0
M = 1000000007
for i in range(1, 1 + n):
	total = (10 * total + int(k[i - 1]) * i) % M
	dp[i] = (dp[i - 1] + total) % M
print(dp[n])


modulo = 1000000007
s = input()
d = 0
i = 0
total = 0
for i in range(0, len(s)):
	digit = ord(s[i]) - ord('0')
	d = (d * 10 + (i + 1) * digit) % modulo
	total += d
total %= modulo
print(total)


digits = input()
res = 0
f = 1
MOD = 10 ** 9 + 7
for i in range(len(digits) - 1, -1, -1):
	res = (res + int(digits[i]) * f * (i + 1)) % MOD
	f = (f * 10 + 1) % MOD
print(res)


from sys import stderr
S = input().strip()
N = len(S)
M = int(1000000000.0 + 7)
T = 0
mult = []
m = 1
for i in range(N):
	mult.append(m)
	m = (10 * m + 1) % M
for i in range(N):
	d = int(S[i])
	m = mult[N - i - 1]
	t = (i + 1) * d * m
	print(' m=%d t=%d' % (m, t), file=stderr)
	T = (T + t) % M
print(T)


s = input()
n = len(s)
md = pow(10, 9) + 7
totalsm = int(s[0])
large_sum = totalsm
for i in range(1, n):
	b = int(s[i])
	large_sum = (10 * large_sum + (i + 1) * b) % md
	totalsm += large_sum
	totalsm = totalsm % md
print(totalsm)


def sumSubstring(n):
	result = 0
	multiplier = 0
	iteration = 0
	numDigits = len(n)
	for char in reversed(n):
		multiplier = (multiplier * 10 + 1) % (10 ** 9 + 7)
		result = (result + int(char) * (numDigits - iteration) * multiplier) % (10 ** 9 + 7)
		iteration += 1
	return str(result)
N = input()
print(sumSubstring(N))


ones = {}

def calc(val, times):
	res = val * ones[times] * (n - times + 1)
	return res
str = input()
n = len(str)
prev = []
summ = 0
for i in range(1, n + 1):
	if i == 1:
		ones[i] = 1
	elif i == 2:
		ones[i] = 11
	else:
		ones[i] = ((ones[i - 1] - ones[i - 2]) * 10 + ones[i - 1]) % 1000000007
for i in range(n):
	times = n - i
	summ += int(str[i]) * ones[times] * (i + 1)
	if summ > 1000000007:
		summ %= 1000000007
print(summ)


def power(a, b):
	if b == 0:
		return 1
	elif b == 1:
		return a
	if b % 2 == 0:
		return power(a * a % (10 ** 9 + 7), b // 2)
	else:
		return a * power(a * a % (10 ** 9 + 7), (b - 1) // 2) % (10 ** 9 + 7)
inp = input().strip(' \n\r')
inp = list(reversed(inp))
sum_of_powers = [0 for i in range(len(inp))]
sum_of_powers[0] = 1
for i in range(1, len(sum_of_powers)):
	sum_of_powers[i] = (sum_of_powers[i - 1] + power(10, i)) % (10 ** 9 + 7)
result = 0
for (idx, val) in enumerate(inp):
	r = len(inp) - idx
	val = int(val)
	result = (result + val * r * sum_of_powers[idx]) % (10 ** 9 + 7)
print(result)


def findAllSubString(word):
	n = len(word)
	result = [0] * (n + 1)
	ones = [0] * (n + 1)
	remainder = [1 / 10] * (n + 1)
	mod = 10 ** 9 + 7
	for i in range(n - 1, -1, -1):
		dig = int(word[i])
		remainder[i] = int(10 * remainder[i + 1]) % mod
		ones[i] = remainder[i] + ones[i + 1]
		result[i] = dig * ones[i] + result[i + 1]
		result[i] = result[i] % mod
	return sum(result) % mod

def main():
	N = input()
	print(findAllSubString(N))
main()


def count(arr, n):
	ans = 0
	for i in range(n):
		d = arr[i]
		if d == '0':
			continue
		bef = i + 1
		aft = n - i
		s_aft = int(d * aft) * bef
		ans += s_aft
	return ans % (10 ** 9 + 7)

def count_2(arr, n):
	ans = 0
	last = 0
	for i in range(n):
		d = int(arr[i])
		c = last * 10 + d * (i + 1)
		last = c
		ans += c
	return ans % (10 ** 9 + 7)
s = input().strip()
n = len(s)
print(count_2(s, n))


s = input()
sol = 0
f = 1
for i in range(len(s) - 1, -1, -1):
	sol += int(s[i]) * f * (i + 1) % (1000000000.0 + 7)
	f = (f * 10 + 1) % (1000000000.0 + 7)
print(int(sol % (1000000000.0 + 7)))


n = str(input())
Sum = 0
t = 1
for i in range(len(n) - 1, -1, -1):
	Sum = (Sum + (ord(n[i]) - ord('0')) * t * (i + 1)) % (10 ** 9 + 7)
	t = (t * 10 + 1) % (10 ** 9 + 7)
print(Sum)


def substring_sum(N):
	L = len(N)
	sub_sums = [0] * L
	sub_sums[0] = int(N[0])
	sub_sums[1] = int(N[1]) + int(N[0]) + int(N[0:2])
	for i in range(2, L):
		sub_sums[i] = (10 * (sub_sums[i - 1] - sub_sums[i - 2]) + sub_sums[i - 1] + (i + 1) * int(N[i])) % (10 ** 9 + 7)
	return sub_sums[L - 1]
N = input().strip()
print(substring_sum(N))


n = input().strip()
base = 10 ** 9 + 7
result = 0
part = 0
for pos in range(len(n)):
	part = (part * 10 + int(n[pos]) * (pos + 1)) % base
	result = (result + part) % base
print(result)


number = list(map(int, input().strip()))
modulus = 10 ** 9 + 7
increment = 1
length = len(number)
summation = 0
for num in number[::-1]:
	summation += num * increment * length
	summation = summation % modulus
	increment = (increment * 10 + 1) % modulus
	length -= 1
print(summation)


s = input()
l = len(s)
x = 0
f = 1
MOD = 10 ** 9 + 7
i = l - 1
while i >= 0:
	x = (x + int(s[i]) * f * (i + 1)) % MOD
	f = (f * 10 + 1) % MOD
	i -= 1
print(x % MOD)


s = input()
mod = 1000000007
l = len(s)
sum = 0
f = 1
for i in range(0, l):
	sum = (sum + int(s[l - i - 1]) * f * (l - i)) % mod
	f = (f * 10 + 1) % mod
print(sum)


s = input()
mod = 1000000007
l = len(s)
sum = 0
f = 1
for i in range(0, l):
	sum = (sum + int(s[l - i - 1]) * f * (l - i)) % mod
	f = (f * 10 + 1) % mod
print(sum)


string = input().rstrip()
maxpow = len(string) + 1
mod = 10 ** 9 + 7
i9 = pow(9, mod - 2, mod)
total = 0
for (i, val) in enumerate(map(int, string), 1):
	total = (total + (pow(10, maxpow - i, mod) - 1) * i9 * i * val % mod) % mod
print(total)


str = list(map(int, input()))
s = 0
i = len(str) - 1
f = 1
MOD = pow(10, 9) + 7
while i >= 0:
	s = (s + str[i] * (i + 1) * f) % MOD
	f = (f * 10 + 1) % MOD
	i -= 1
print(s)


def substring(s):
	mult = 1
	p = len(s)
	res = 0
	for num in s[::-1]:
		res += int(num) * mult * p % 1000000007
		p -= 1
		mult = (mult * 10 + 1) % 1000000007
	return res % 1000000007
print(substring(input()))


def substrings(s):
	n = len(s)
	ret = 0
	f = 1
	for i in range(n - 1, -1, -1):
		ret = (ret + int(s[i]) * f * (i + 1)) % mod
		f = (10 * f + 1) % mod
	return ret
st = input().strip()
n = len(st)
mod = 10 ** 9 + 7
ans = substrings(st)
print(ans)


import sys
s = input().strip()
l = list(s)
a = [int(x) for x in l]
L = len(s)
mod_div = 10 ** 9 + 7
prev = 0
m = 10 ** (-1)
total = 0
for i in range(0, L):
	jj = L - i
	m = m * 10 % mod_div
	mult = (m + prev) % mod_div
	total += a[jj - 1] * mult * jj % mod_div
	prev = mult
print(int(total % mod_div))


n = input()
l = list(n)
f = 1
l.reverse()
mod = 10 ** 9 + 7
n = len(l)
res = 0
for i in range(n):
	res = (res + int(l[i]) * (n - i) * f) % mod
	f = (f * 10 + 1) % mod
print(res)


s = input()
n = len(s)
m = 10 ** 9 + 7
s = [int(x) for x in s]
total = 0
mult = 1
for i in range(n):
	total += mult * (n - i) * s[n - i - 1]
	total = total % m
	mult = (mult * 10 + 1) % m
print(total)


n = input()
n = list(n)
m = 1000000007
n = list(map(int, n))
summation = 0
f = 1
for i in range(0, len(n)):
	x = len(n) - i - 1
	summation = (summation + n[x] * (x + 1) * f % m) % m
	f = (f * 10 + 1) % m
print(summation)


a = input()
L = len(a)
total = 0
reduce = 10 ** 9 + 7
ones = 1
for i in range(L):
	total = (total + (L - i) * (int(a[L - i - 1]) * ones)) % reduce
	ones = (10 * ones + 1) % reduce
print(total)


number = input()
sum_ = 0
tens = 1
for (pos, n) in enumerate(reversed(number)):
	n = int(n)
	sum_ += n * (len(number) - pos) * tens
	sum_ %= 1000000007
	tens = (tens * 10 + 1) % 1000000007
print(sum_)


N = str(input().strip())
n = len(N)
ans = 0
q = 0
m = lambda x: x % 1000000007
for i in range(n):
	q = m(q * 10 + 1)
	k = int(N[n - 1 - i])
	ans = m(ans + q * (n - i) * k)
print(ans)


def main():
	s = input().strip()
	l = len(s)
	dp = l * [0]
	dp[0] = int(s[0])
	m = 10 ** 9 + 7
	for i in range(1, l):
		dp[i] = ((i + 1) * int(s[i]) + 10 * dp[i - 1]) % m
	for i in range(1, l):
		dp[i] = (dp[i] + dp[i - 1]) % m
	print(dp[-1] % (10 ** 9 + 7))
main()


line = list(map(int, input()))
s = 0
mult = 1
for i in range(len(line) - 1, -1, -1):
	s = (s + line[i] * mult * (i + 1)) % 1000000007
	mult = (mult * 10 + 1) % 1000000007
print(s)


inp = input()
i = 0
j = len(inp)
ans = 0
mul = 1
MOD = 10 ** 9 + 7
while i < len(inp):
	ans = (ans + int(inp[j - i - 1]) * (mul * (j - i)) % MOD) % MOD
	mul = (mul * 10 + 1) % MOD
	i += 1
print(ans)


def solution(n):
	s = 0
	prev_sum = 0
	for (i, d) in enumerate(n):
		s_ = prev_sum * 10 + (i + 1) * int(d)
		s += s_
		prev_sum = s_
	return s % (10 ** 9 + 7)
n = input()
print(solution(n))


def samsum(s):
	l = len(s)
	o0 = ord('0')
	sm = 0
	f = 1
	for i in range(l - 1, -1, -1):
		sm = (sm + (ord(s[i]) - o0) * (i + 1) * f) % 1000000007
		f = (f * 10 + 1) % 1000000007
	return sm
print(samsum(input().strip()))