CF1601F.Two Sorts

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Integers from 11 to nn (inclusive) were sorted lexicographically (considering integers as strings). As a result, array a1,a2,,ana_1, a_2, \dots, a_n was obtained.

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

xmodyx \mod y here means the remainder after division xx by yy . This remainder is always non-negative and doesn't exceed y1y - 1 . For example, 5mod3=25 \mod 3 = 2 , (1)mod6=5(-1) \mod 6 = 5 .

输入格式

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

输出格式

Print one integer — the required sum.

输入输出样例

  • 输入#1

    3

    输出#1

    0
  • 输入#2

    12

    输出#2

    994733045
  • 输入#3

    21

    输出#3

    978932159
  • 输入#4

    1000000000000

    输出#4

    289817887

说明/提示

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

  • aa is a prefix of bb , but aba \ne b ;
  • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb .

For example, 4242 is lexicographically smaller than 66 , because they differ in the first digit, and 4<64 < 6 ; 42<42042 < 420 , because 4242 is a prefix of 420420 .

Let's denote 998244353998244353 as MM .

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

  • (11)modM=0modM=0(1 - 1) \mod M = 0 \mod M = 0
  • (22)modM=0modM=0(2 - 2) \mod M = 0 \mod M = 0
  • (33)modM=0modM=0(3 - 3) \mod M = 0 \mod M = 0

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

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

  • (11)modM=0modM=0(1 - 1) \mod M = 0 \mod M = 0
  • (210)modM=(8)modM=998244345(2 - 10) \mod M = (-8) \mod M = 998244345
  • (311)modM=(8)modM=998244345(3 - 11) \mod M = (-8) \mod M = 998244345
  • (412)modM=(8)modM=998244345(4 - 12) \mod M = (-8) \mod M = 998244345
  • (52)modM=3modM=3(5 - 2) \mod M = 3 \mod M = 3
  • (63)modM=3modM=3(6 - 3) \mod M = 3 \mod M = 3
  • (74)modM=3modM=3(7 - 4) \mod M = 3 \mod M = 3
  • (85)modM=3modM=3(8 - 5) \mod M = 3 \mod M = 3
  • (96)modM=3modM=3(9 - 6) \mod M = 3 \mod M = 3
  • (107)modM=3modM=3(10 - 7) \mod M = 3 \mod M = 3
  • (118)modM=3modM=3(11 - 8) \mod M = 3 \mod M = 3
  • (129)modM=3modM=3(12 - 9) \mod M = 3 \mod M = 3

As a result, (0+998244345+998244345+998244345+3+3+3+3+3+3+3+3)mod109+7(0 + 998244345 + 998244345 + 998244345 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) \mod 10^9 + 7 == 2994733059mod109+72994733059 \mod 10^9 + 7 == 994733045994733045

首页