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: Accepted)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int mod=1e9+7;
int add(int x,int y)
{
  x+=y;
  if(x>=mod) x-=mod;
  if(x<0) x+=mod;
  return x;
}
int mult(int x,int y)
{
  ll tmp=(ll)x*y;
  if(tmp>=mod) tmp%=mod;
  return tmp;
}
int pow1(int x,int y)
{
  int ans=1;
  while(y)
    {
      if(y&1) ans=mult(ans,x);
      x=mult(x,x);
      y>>=1;
    }
  return ans;
}
int s,ans;
int calc(int x)
{
  int cnt=0;
  while(x) x/=10,cnt++;
  return cnt;
}
const int N=25000000;
int sum[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  cin>>s;
  //first take if range belongs to only within same digits
  int sq=sqrt(s);
  rep(i,1,sq+1)
    {
      if((s%i)!=0) continue;
      int x=s/i;
      int curr=mult(9,pow1(10,i-1));
      if(i>7) ans=add(ans,add(curr,-(x-1)));
      if(x==i) continue;
      if(s/i>7) ans=add(ans,add(mult(9,pow1(10,x-1)),-(i-1)));
    }
  //look for adjacent, there can;t be more than 2 adjacent if x>8
  /* ax+b(x+1)=S
     so a=(S-b)/x - b, where x is number of digits,
     so b will be of the form k*x+(S%x)
     so a = (S/x + k - (k*x + S%x)), it should be greater than 0,
     so k< (S/x - S%x) / (x-1)*/
  rep(i,8,s)
    {
      if(s%i==0)
	{
	  int tmp=s/i;
	  if(tmp%(i+1)==0) ans=add(ans,max(0,-1+tmp/(i+1)));
	  else ans=add(ans,tmp/(i+1));
	}
      else
	{
	  int k=s/i-(s%i);
	  if(k<0) continue;
	  if(k%(i+1)==0) ans=add(ans,k/(i+1));
	  else ans=add(ans,1+k/(i+1));
	}
    }
  //for first 7, there can be any number of adjacent
  rep(i,1,N)
    sum[i]=sum[i-1]+calc(i);
  int i=1,j=1;
  while(i<1e7)
    {
      while(j<N && sum[j]-sum[i-1]<s) j++;
      if(j<N && sum[j]-sum[i-1]==s) ans=add(ans,1);
      i++;
    }
  cout<<ans<<endl;
  return 0 ;
}