QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#4057. Substring Statistics

Statistics

Little D learned about suffix automata when he was four and a half years old.

You are given a string $S$ of length $n$. Initially, $T_0 = S$. In each step, you can delete the first or the last character of $T_i$ to obtain a new string $T_{i+1}$. After $n-1$ operations, we obtain a string $T_{n-1}$ consisting of a single character. Depending on the choices made at each step, there are $2^{n-1}$ possible sequences of operations. Note that even if deleting the first or last character results in the same string, we still treat them as two distinct operation sequences.

For a string $T$, let $occ(T)$ denote the number of occurrences of $T$ as a substring in $S$. For example, $occ(\textsf{aaa}, \textsf{aaabaaa}) = 3$.

For an operation sequence, its contribution is defined as $\prod_{i=1}^{n-1} occ(T_i)$. Calculate the sum of contributions over all possible operation sequences. Since the answer can be very large, output the result modulo $998\,244\,353$.

Input

A single line containing a string $S$. It is guaranteed that $S$ consists only of lowercase English letters.

Output

A single integer representing the answer.

Examples

Input 1

zzz

Output 1

24

Input 2

abbab

Output 2

53

Input 3

See the provided files.

Subtasks

There are 20 test cases in total.

For test cases 1–5, $|S| \leq 5\, 000$.

For test cases 6–8, each character of $S$ is generated independently and uniformly at random from a and b.

For test cases 9–14, $|S| \leq 6 \times 10^4$.

For all test cases, $1 \leq |S| \leq 10^5$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.