#P6045. 后缀树

后缀树

Description

For a string SS, we define S|S| as the length of SS.

Next, we define SiS_i as the ii-th character of SS, and SL...RS_{L...R} as the string formed by concatenating, from left to right, the LL-th character to the RR-th character of SS.

Given nn, find how many different strings SS satisfy all of the following:

  • S=n|S|=n.
  • SS contains only lowercase letters.
  • There does not exist an integer i[1,n)i \in [1,n) such that S1...iS_{1...i} is a substring of Si+1...nS_{i+1...n}.

For the third constraint, in simpler words: there is no way to split the string into two parts such that the first part is a substring of the second part.

Two strings SS and TT are different if and only if ST|S|\neq|T| or i[1,S] SiTi\exists i \in [1,|S|] \ S_i \neq T_i. If you do not know what this means, you can just think that they look different.

Poor Eztsu cannot solve it, so you need to help her.

The answer may be very large. You only need to output the value of the answer modulo 998244353998244353.

Additional note:

SS is a substring of TT if and only if there exist L,R[1,T]L,R \in [1,|T|] such that TL...R=ST_{L...R}=S.

Input Format

One line containing a positive integer nn, as described in the statement.

Output Format

One line containing an integer: the answer modulo 998244353998244353.

2
650
105383595
114514

Hint

Sample Explanation

For the first sample, it is not hard to see that the string satisfies the requirements if and only if the two characters are different. Therefore, the answer is 26×262626 \times 26 - 26, which can be understood as the number of ways to choose any two characters minus the number of ways where the two characters are the same.


Constraints

This problem uses bundled testdata.

For all test points, 1n1091 \leq n \leq 10^9 is guaranteed.

Subtask 1 (17 pts)\text{Subtask 1 (17 pts)} n4n \leq 4.

Subtask 2 (78 pts)\text{Subtask 2 (78 pts)} n2×103n \leq 2\times 10^3.

Subtask 3 (5 pts)\text{Subtask 3 (5 pts)} No special constraints.


Hint

There are 2626 lowercase letters in total.

Translated by ChatGPT 5