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: Time Limit Exceeded)

#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y,z;
    //string r;
    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};
struct S
{
    int x,y;
};
vector<P> v[100333];
//bitset<4001000> bit;
int a,c,i,b,k,d,n,m,e=1987654321;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[200][200];
long long o[1005522];
long long j[200100];
int dx[10]={0,1,0,-1},dy[10]={1,0,-1,0},dz[10]={0,0,0,0,1,-1};

long long x,y,z,mod=1000000007;
P u[122222][333];
//int j[31][11111];

stack<S> s;
queue<int> q;
queue<int> q1;

//deque<int> de;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<string,string > p;
//list<int> l;
string r,r1,r2,r3;
//char r[33][33];

bool as(int a,int b)
{
    return a>b;
}

int f(int a)
{
    int i=0;
    for(;a;a/=10,i++);
    return i;
}
long long g(int a)
{
    if(a==0) return 1;
    long long x=g(a/2);
    x*=x;
    x*=mod;
    if(a&1) x*=10,x%=mod;
    return x;
}
int main()
{
    scanf("%d",&a);
    n=1;
    m=1;
    i=1;
    for(;n<10000000;)
    {
        if(i>=a)
        {
            if(i==a)
            {
                //printf("@%d %d\n",n,m);
                x++;
            }
            i-=f(n);
            n++;
        }
        else
        {
            m++;
            i+=f(m);
        }
        x%=mod;
    }

    //for(int t=2;t<=a;t++)
      //  g[t]=z[t-1]*10%mod;
      y=100000000;
      z=10000000;
    for(int t=7;t<a;t++)
    {
        //printf("%d %lld\n",t,x);
        if(a%(t+1))
        {
            if(a/(t+1)>a%(t+1))
            {
            x+=max((a/(t+1)-a%(t+1))/(t+2)+1,0);
            if(a%(t+2)==0) x+=mod-1;
            }
        }
        else
        {
            x+=y-z-(a/(t+1))+1+mod;
            x+=max((a/(t+1)-a%(t+1))/(t+2),0);
            if(a%(t+2)==0) x+=mod-1;
        }
        y=y*10%mod;
        z=z*10%mod;
        x%=mod;
    }
    printf("%lld",x);
}