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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;
int num(int x){
    int a = 10;
    int ans = 1;
    while (x >= a){
        ans++;
        a *= 10;
    }
    return ans;
}
int pw(int a, int b){
	int ans = 1;
	int st = a;
	for (int i=0; i < 30; i++){
		int ba = (1LL<<i)&b;
		if (ba != 0){
			ans *= st;
			ans %= MOD;
		}
		st*=st;
		st%=MOD;
	}
	return ans;
}
int solve(int s) {
    ios_base::sync_with_stdio(false);
    int ans = 0;
    int S = 0;
    int i = 1;
    while (true){
        int pl = num(i);
        if (S + pl <= s){
            i++;
            S += pl;
        }
        else break;
    }
    if (s == S) ans++;
    for (int j=2; j < 10000000; j++){
        S -= num(j-1);
        while (true){
            int pl = num(i);
            if (S + pl <= s){
                i++;
                S += pl;
            }
            else break;
        }
        if (s == S) ans++;
    }
    //cout << ans << endl;
    int now = 90000000;
    for (int j=8; j <= 1000000; j++){
        int X = -s;
        int Y = s;
        int p = s/(j+1) + 1;
        X += p*(j+1);
        Y -= p*j;
        if (Y > 0){
            ans += (Y-1) / j + 1;
            ans %= MOD;
        }
        if (Y % j == 0 && Y >= 0){
            X += (Y/j) * (j+1);
            ans += now - X + 1;
            ans %= MOD;
        }
        now *= 10;
        now %= MOD;
    }
    //cout << ans << endl;
    if (s > 1000000){
        for (int a=1; a <= 100; a++){
            for (int b=1; b <= 100; b++){
                if ((s-b) % (a+b) != 0) continue;
                int XX = (s-b) / (a+b);
                if (XX > 1000000){
                    //cout << a << " " << b << endl;
                    ans++;
                }
            }
        }
        //cout << ans << endl;
        for (int j=1; j <= 100; j++){
            if (s/j > 1000000 && s % j == 0){
				int G = pw(10, s/j-1);;
                int XX = j;
                ans += G - XX + 1;
            }
        }
    }
    ans %= MOD;
    ans += MOD;
    return ans%MOD;
}

signed main(){
    int s;
    cin >> s;
    int A = solve(s);
    cout << A << endl;
}