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>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int mod = 1000000007;
const int N = 50000001;

int _prev[N];

LL _pow(LL a, LL b) {
  if(!b) return 1;
  if(b == 1) return a;
  if(b == 2) return a * a % mod;
  if(b & 1) {
    return a * _pow(a,b-1) % mod;
  }
  return _pow(_pow(a,b/2),2);
}

int main() {
  int n;
  S(n);
  int ans = 0;
  rep(i,1,n/8+1) {
    if(n % i == 0) {
      ans += _pow(10, n / i) - _pow(10, (n / i) - 1) - (i - 1);
      ans %= mod;
      if(ans < 0) ans += mod;
    } else {
      ans++;
      if(ans >= mod) ans -= mod;
    }
  }
  int d = 1;
  int sm = 0;
  int p = 0;
  rep(i,1,N) {
    if(i == 10 || i == 100 || i == 1000 || i == 10000 || i == 100000 || i == 1000000 || i == 10000000) {
      d++;
      p = 0;
    }
    sm += d;
    p += d;
    if(sm >= N) break;
    _prev[sm] = i;
    if(sm >= n && _prev[sm - n] && i - _prev[sm - n] > n / 8) {
      ans++;
      if(ans == mod) ans = 0;
    } else if(sm == n && i > n / 8) {
      ans++;
      if(ans == mod) ans = 0;
    }
  }
  P(ans);
  return 0;
}