Problem :

https://www.hackerrank.com/challenges/sam-and-substrings/problem


My Solution :

#!/usr/bin/env python3

def substrings(n):
    m = 10**9 + 7
    dp = [int(n[0])]
    for i in range(1, len(n)):
        s = ((i+1)*int(n[i]) + 10*dp[i-1]) % m
        dp.append(s)
    ret = 0
    for s in dp:
        ret = (ret + s) % m
    return ret


n = input().strip()
result = substrings(n)
print(result)