Problem:
Score : 900 points

Problem Statement

For a positive integer n, let us define f(n) as the number of digits in base 10.

You are given an integer S.
Count the number of the pairs of positive integers (l, r) (l \leq r) such that f(l) + f(l + 1) + ... + f(r) = S, and find the count modulo 10^9 + 7.

Constraints

1 \leq S \leq 10^8

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer.

Sample Input 1

1

Sample Output 1

9

There are nine pairs (l, r) that satisfies the condition: (1, 1), (2, 2), ..., (9, 9).

Sample Input 2

2

Sample Output 2

98

There are 98 pairs (l, r) that satisfies the condition, such as (1, 2) and (33, 33).

Sample Input 3

123

Sample Output 3

460191684

Sample Input 4

36018

Sample Output 4

966522825

Sample Input 5

1000

Sample Output 5

184984484

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn pow_mod(base: usize, power: usize, modulo: usize) -> usize {
    let mut base = base;
    let mut power = power;
    let mut ans = 1;
    while power > 0 {
        if power & 1 == 1 { ans = ans * base % modulo; }
        power >>= 1;
        base = base * base % modulo;
    }
    ans
}

const MOD: usize = 1e+9 as usize + 7;

fn calc_small(s: usize, v: usize) -> usize {
    let mut v = v;
    let mut w = 1;
    let mut base = 1;
    while base * 10 <= v { w += 1; base *= 10; }
    let mut sum = 0;
    loop {
        let rest = base * 10 - v;
        let need = (s - sum) / w;
        if need <= rest {
            v += need;
            sum += need * w;
            break;
        }
        sum += rest * w;
        base *= 10;
        v = base;
        w += 1;
    }
    if sum == s { 1 } else { 0 }
}

fn calc(s: usize, w: usize) -> usize {
    let mut ret = 0;
    if w < 8 {
        let left = std::cmp::max(1, usize::pow(10, w as u32 - 1));
        let right = usize::pow(10, w as u32);
        for i in left..right {
            ret += calc_small(s, i);
        }
    } else {
        let cnt = s / w;
        let rest = s % w;
        if rest == 0 {
            ret = (pow_mod(10, w, MOD) + MOD - pow_mod(10, w - 1, MOD) + MOD - cnt) % MOD;
        }
        if rest < cnt {
            ret = (ret + 1 + (cnt - rest - 1) / (w + 1)) % MOD;
        }
        // println!("{} {} {}", w, cnt, rest);
    }
    ret % MOD
}

fn main() {
    let s: usize = read();
    // println!("{}", calc(123, 3));
    //return;
    let mut min_digit = 1;
    let mut ans = 0;
    loop {
        ans = (ans + calc(s, min_digit)) % MOD;
        if min_digit * min_digit > s { break; }
        min_digit += 1;
    }
    for i in 1.. {
        let target = s / i;
        if target <= min_digit { break; }
        ans = (ans + calc(s, target)) % MOD;
    }
    println!("{}", ans);
}