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

Solutions:
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)


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)


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)


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))


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])


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)


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)


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_)