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 dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define DMAX 
#define NMAX 
#define MMAX 
#define MOD 1000000007

using namespace std;

long long n, k, x, v[230000100];
string s;


template<class T>
ostream& operator<<(ostream& out, vector<T> v)
{
	out << v.size() << '\n';
	for(auto e : v)
		out << e << ' ';
	return out;
}

long long pw(long long base, long long exp) {
	if(exp == 1) return base;
	if(exp == 0) return 1LL;

	long long g = pw(base, exp / 2);
	g = g * g;
	g %= MOD;
	if(exp % 2) return (g * base) % MOD;
	else return g;
}

inline long long nrc(long long k) {
	long long ans = 0;
	while(k) ans++, k/=10;
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	// for(long long i = 1; i < 100000000; i++)

	cin >> n;
	long long ans = 0;
	long long j = 1, sum = 0, p10 = 9;
	// 
	// ans = n / 8;
	for(int t = 1; t <= n / 8; t++) {
		if(n % t == 0) {
			long long nr = n / t;
			long long g = (long long)(pw(10, nr) - pw(10, nr - 1) - t + 1) % MOD;
			if(g < 0) g += MOD;
			ans += g;
			ans %= MOD;
		} 
		else ans++;
	}

	// dbg(ans);
	for(int i = 0; i < 10; i++) 
		v[i] = 1;
	
	for(long long i = 10; i <= 23000000; i++)
		v[i] = v[i / 10] + 1;

	for(int l = 1, r = 2, sum = v[1]; r <= 23000000;sum -= v[l], l++) {
		while(sum < n) sum += v[r], r++;
		ans += (sum == n);
	}

	cout << ans % MOD << '\n';
}