Under construction

Still being built. Things may change

Interesting celebrations

Interview

Time limit1sMemory limit1024 MB

Summary
Count the subsequences of string s that equal one of the words seq_1 to seq_26, modulo 998244353.
Level

Medium5 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Problem

Every year the Myers family celebrates Halloween, and the celebrations start to feel repetitive. They want to vary the celebrations so Halloween does not get boring.

There are exactly 2626 known ways to celebrate Halloween, and the ii-th way can be denoted by the ii-th letter of the Latin alphabet (from a to z). The Myers family has celebrated Halloween for a long time and has kept records of how they celebrated each year.

They are curious how many subsequences of years (not necessarily contiguous) are interesting. There are exactly 2626 interesting sequences of celebration methods, defined as follows:

  • seq_1=\mathtt{seq}\_1 = <<a>>
  • seq_i+1=seq_i+<<c_i+1>>+seq_i\mathtt{seq}\_{i+1} = \mathtt{seq}\_i + \text{<<}c\_{i+1}\text{>>} + \mathtt{seq}\_i, where c_i+1c\_{i+1} is the (i+1)(i+1)-th letter of the Latin alphabet.

So the first three interesting sequences are <<a>>, <<aba>>, and <<abacaba>>.

You are given a string ss, whose ii-th character is the celebration method in the ii-th year. Help the Myers family count the subsequences of ss that are interesting. Since the count can be very large, compute it modulo 998244353998244353. A subsequence is a string obtained by deleting some, possibly zero, characters.

Input

The only line contains a string ss (1⩽∣s∣⩽5000)(1 \leqslant |s| \leqslant 5000).

Output

Print the number of subsequences of this string that are of the form seq_i\mathtt{seq}\_i, modulo 998244353998244353.

Hint

From the string <<abacaba>>, you can choose 44 subsequences <<a>>, 66 subsequences <<aba>>, and one subsequence <<abacaba>>.

Examples2

  1. Example 1

    Input
    abacaba
    
    Expected output
    11
    
  2. Example 2

    Input
    b
    
    Expected output
    0