luogu#P10272. 在四方城外

在四方城外

Background

Willow flowers, green hills, and moonlight.

The scent of wine in poems, and the scent of wine outside poems.

The sky inside the city, and the sky outside the city.

Word by word, stroke by stroke, what is understood, what is still hazy.

Look and look, learn and learn. The world is like murky wine; you only know its taste after you drink it.

Problem Description

Define the extension operation on a string SS as:

  • Find the longest border\text{border} TT of SS.

  • Set SS+TS'\leftarrow S+T.

Note: in this problem, border\text{border} means a proper border\text{border} (that is, the string itself is not counted as a border\text{border}).

Let the weight of an extension operation be the length of the string after extension, i.e. S|S'|. Please compute the sum of weights from the LL-th extension of string SS to the RR-th extension.

Since the result may be very large, output the answer modulo 998244353998244353.

Input Format

The first line contains a string SS.

The second line contains two integers L,RL,R.

Output Format

Output one number, i.e. the answer modulo 998244353998244353.

ababcab
1 3
39
aa
3 5
59

Hint

Explanation for Sample 1

The 11-st extension: ababcab[ab], with weight 99.

The 22-nd extension: ababcabab[abab], with weight 1313.

The 33-rd extension: ababcabababab[abab], with weight 1717.

The sum of weights is 9+13+17=399+13+17=39.

Constraints

For 30%30\% of the testdata, 1S1001 \le |S| \le 100 and 1L,R101 \le L,R \le 10.

For 60%60\% of the testdata, 1L,R1061 \le L,R \le 10^6.

For the other 10%10\% of the testdata, borderS=S1\text{border}_{S}=|S|-1.

For 100%100\% of the testdata, 1S1061 \le |S| \le 10^6 and 1LR1091 \le L \le R \le 10^9. The input consists only of integers and lowercase letters.

Translated by ChatGPT 5