Codeforces Round 751 (Div. 1)
F
Two Sorts
Codeforces
3400
原题
← E→
翻译中…

Integers from $1$ to $n$ (inclusive) were sorted lexicographically (considering integers as strings). As a result, array $a_1, a_2, \dots, a_n$ was obtained.

翻译中…

Calculate value of $(\sum_{i = 1}^n ((i - a_i) \mod 998244353)) \mod 10^9 + 7$.

翻译中…

$x \mod y$ here means the remainder after division $x$ by $y$. This remainder is always non-negative and doesn't exceed $y - 1$. For example, $5 \mod 3 = 2$, $(-1) \mod 6 = 5$.

翻译中…

Input

翻译中…

The first line contains the single integer $n$ ($1 \leq n \leq 10^{12}$).

翻译中…

Output

翻译中…

Print one integer — the required sum.

翻译中…

Note

翻译中…

A string $a$ is lexicographically smaller than a string $b$ if and only if one of the following holds:

翻译中…
  • $a$ is a prefix of $b$, but $a \ne b$;
  • in the first position where $a$ and $b$ differ, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$.
翻译中…

For example, $42$ is lexicographically smaller than $6$, because they differ in the first digit, and $4 \lt 6$; $42 \lt 420$, because $42$ is a prefix of $420$.

翻译中…

Let's denote $998244353$ as $M$.

翻译中…

In the first example, array $a$ is equal to $[1, 2, 3]$.

翻译中…
  • $(1 - 1) \mod M = 0 \mod M = 0$
  • $(2 - 2) \mod M = 0 \mod M = 0$
  • $(3 - 3) \mod M = 0 \mod M = 0$
翻译中…

As a result, $(0 + 0 + 0) \mod 10^9 + 7 = 0$

翻译中…

In the second example, array $a$ is equal to $[1, 10, 11, 12, 2, 3, 4, 5, 6, 7, 8, 9]$.

翻译中…
  • $(1 - 1) \mod M = 0 \mod M = 0$
  • $(2 - 10) \mod M = (-8) \mod M = 998244345$
  • $(3 - 11) \mod M = (-8) \mod M = 998244345$
  • $(4 - 12) \mod M = (-8) \mod M = 998244345$
  • $(5 - 2) \mod M = 3 \mod M = 3$
  • $(6 - 3) \mod M = 3 \mod M = 3$
  • $(7 - 4) \mod M = 3 \mod M = 3$
  • $(8 - 5) \mod M = 3 \mod M = 3$
  • $(9 - 6) \mod M = 3 \mod M = 3$
  • $(10 - 7) \mod M = 3 \mod M = 3$
  • $(11 - 8) \mod M = 3 \mod M = 3$
  • $(12 - 9) \mod M = 3 \mod M = 3$
翻译中…

As a result, $(0 + 998244345 + 998244345 + 998244345 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) \mod 10^9 + 7$ $=$ $2994733059 \mod 10^9 + 7$ $=$ $994733045$

翻译中…

样例

Input #1
3
Output #1
0
InputCopy OutputCopy
Input #2
12
Output #2
994733045
InputCopy OutputCopy
Input #3
21
Output #3
978932159
InputCopy OutputCopy
Input #4
1000000000000
Output #4
289817887
InputCopy OutputCopy
题目信息
题号
1601F
时间限制
4 s
内存限制
512 MB
标签
二分
DFS 及类似
数学
折半搜索

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。