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>

using namespace std;

long mod = 1e9 + 7;
long L(long d) {
	if (!d) return 1;
	auto t = L(d / 2);
	return (d % 2 ? (t * t%mod) * 10 : t * t) % mod;
}
int main()
{
	long s;
	cin >> s;
	long res = 0, d = 0, d8 = 0;
	for (int i = 1; i <= s / i; i++) {
		if (s%i) continue;
		d++;
		auto j = s / i;
		if (i < 9) res += max(0l, L(i - 1) * 9 - j + 1), d8++;
		else res += L(i - 1) * 9 - j + 1 + mod;
		res %= mod;
		if (i == j) break;
		d++;
		if (j < 9) res += max(0l, L(j - 1) * 9 - i + 1), d8++;
		else res += L(j - 1) * 9 - i + 1 + mod;
		res %= mod;
	}
	res = (res + (s - 1) / 8 + d8 - d) % mod;
	long l = 1, ll = 1, r = 1, rr = 1, t = 1, LL = 10, RR = 10;
	while (r < 20000000) {
		if (ll == rr || t < s) {
			if (++r == RR) rr++, RR *= 10;
			t += rr;
		}
		else {
			if (t == s) res++, res %= mod;
			t -= ll;
			if (++l == LL) ll++, LL *= 10;
		}
	}
	cout << res << endl;
	return 0;
}