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 <cstdio>

const int p=1000000007;

int i,n,l,r,s,t,w;

inline int calc(int x)
{
	if (x<10) return 1;
	if (x<100) return 2;
	if (x<1000) return 3;
	if (x<10000) return 4;
	if (x<100000) return 5;
	if (x<1000000) return 6;
	return 7;
}

inline int power(int x,int y)
{
	int s=1;
	for (int i=30;i>=0;i--)
	{
		s=1LL*s*s%p;
		if ((1<<i)&y)
			s=1LL*s*x%p;
	}
	return s;
}

int main()
{
	scanf("%d",&n);
	for (i=7;i<=n;i++)
	{
		if (! (n%i))
			s=(s+9LL*power(10,i-1)-(n/i)%p+p)%p;
		if (n>1LL*(n%i)*(i+1))
		{
			t=((n-(n%i)*(i+1))/i)/(i+1);
			if (((n-(n%i)*(i+1))/i)%(i+1))
				t++;
			s=(s+t)%p;
		}
	}
	t=0;
	for (l=1,r=1;calc(l)<=6;l++)
	{
		for (;t<n;r++)
			t=t+calc(r);
		if (t==n)
			s++;
		t=t-calc(l);
	}
	printf("%d",s%p);
	return 0;
}