F - Square Subsequence Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500500

問題文

英小文字のみからなる文字列 SS が与えられます。 下記の条件を満たす空でない文字列 TT の個数を 998244353998244353 で割ったあまりを出力してください。

TT22 つ連結して得られる文字列 TTTT が、SS に(連続とは限らない)部分列として含まれる。

制約

  • SS は英小文字のみからなる長さ 11 以上 100100 以下の文字列

入力

入力は以下の形式で標準入力から与えられる。

SS

出力

答えを出力せよ。


入力例 1Copy

Copy
ababbaba

出力例 1Copy

Copy
8

問題文中の条件を満たす文字列 TT は、aaaabababbababbb88 個です。


入力例 2Copy

Copy
zzz

出力例 2Copy

Copy
1

問題文中の条件を満たす文字列 TT は、z のみです。 S=S1S2S3=S = S_1S_2S_3 = zzz から、文字列 zz を部分列として得る方法は、 S1S2=S_1S_2 = zzS1S3=S_1S_3 = zzS2S3=S_2S_3 = zz33 通りありますが、文字列 z は答えに 11 回だけ寄与することに注意してください。


入力例 3Copy

Copy
ppppqqppqqqpqpqppqpqqqqpppqppq

出力例 3Copy

Copy
580

Score : 500500 points

Problem Statement

You are given a string SS consisting of lowercase English letters. Print the number of non-empty strings TT that satisfy the following condition, modulo 998244353998244353.

The concatenation TTTT of two copies of TT is a subsequence of SS (not necessarily contiguous).

Constraints

  • SS is a string consisting of lowercase English letters whose length is between 11 and 100100, inclusive.

Input

The input is given from Standard Input in the following format:

SS

Output

Print the answer.


Sample Input 1Copy

Copy
ababbaba

Sample Output 1Copy

Copy
8

The eight strings satisfying the condition are a, aa, ab, aba, b, ba, bab, and bb.


Sample Input 2Copy

Copy
zzz

Sample Output 2Copy

Copy
1

The only string satisfying the condition is z. Note that this string contributes to the answer just once, although there are three ways to extract the subsequence zz from S=S1S2S3=S = S_1S_2S_3 = zzz: S1S2=S_1S_2 = zz, S1S3=S_1S_3 = zz, and S2S3=S_2S_3 = zz.


Sample Input 3Copy

Copy
ppppqqppqqqpqpqppqpqqqqpppqppq

Sample Output 3Copy

Copy
580


2025-03-29 (Sat)
15:58:52 +00:00