#P6654. [YsOI2020] 归零

[YsOI2020] 归零

Background

Ysuperman especially likes playing counting games.

Actually, this problem was originally planned to be called “亦旧亦久罢以龄”, but I saw that other problem names are all two characters long, so it would not be good to use such a long name.

Problem Description

In his free time, Ysuerpman chooses to kill time with a calculator. He inputs a very long decimal number SS. How long is it? It has nn digits in total. For convenience, let the digit on the ii-th position from low to high be SiS_i (the index starts from 11).

Each time, Ysuerpman will choose a non-zero digit position and perform “rounding”. Specifically, suppose he performs “rounding” on the ii-th digit:

  • If Si<5S_i<5, then subtract Si10i1S_i \cdot 10^{i-1} from SS.
  • If Si5S_i\ge5, then add 10i10^i to SS, and then subtract Si10i1S_i \cdot 10^{i-1}.

After several operations, SS will always become 00. Now the question is: how many different plans are there that make SS become 00? Two plans are different if and only if there exists some operation where the chosen digit position is different.

Input Format

A high-precision number SS.

Output Format

The number of different plans that make SS become 00, modulo 998244353998244353.

5

1

45

2

55

4

3333

24

999999

16336

1919810

3461

11451419

210000

Hint

Sample Explanation

Sample Explanation 11

5100\underline5\to \underline10 \to 0

There is 11 plan in total.

Sample Explanation 22

455100\underline{4}5\to\underline{5}\to\underline10\to 0

$4\underline{5}\to\underline{5}0\to \underline100 \to 0$

There are 22 plans in total.

Sample Explanation 33

$\underline{5}5\to\underline{1}05\to\underline{5}\to\underline{1}0 \to 0$

$\underline{5}5\to10\underline{5}\to\underline{1}10\to \underline10 \to 0$

$\underline{5}5\to10\underline{5}\to1\underline{1}0\to \underline100 \to 0$

$5\underline{5}\to\underline{6}0\to \underline100 \to 0$

There are 44 plans in total.

Constraints

This problem uses bundled testdata.

subtask\rm{subtask} nn SiS_i\in Score
00 6\le 6 [0,9][0,9] 55
11 15\le 15 1313
22 40\le40 [0,4][0,4] 55
33 40\le 40 {9}\{9\} 1212
44 40\le40 [5,8][5,8] 1515
55 40\le 40 [0,9][0,9] 3030
66 64\le 64 2020

For 100%100\% of the data, 1n641\le n \le 64, and SS has no leading zeros.

Hint

The time limit for this problem is 1145 ms1145\ \rm{ms}.

The problem is not hard.

Translated by ChatGPT 5