Since we need powers of 10 for counting , it 's better to  pre store them along with their  modulo with 1e9 + 7 for counting
st = 1 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT powers [ i ] = st NEW_LINE st *= 10 NEW_LINE st %= mod NEW_LINE DEDENT