#abc249e. E - RLE

E - RLE

Score : 500500 points

问题描述

考虑以下过程,给定一个由小写英文字母组成的字符串 XX,获取一个新的字符串:

  • 在相邻字符不同的位置将字符串 XX 断开。
  • 对于每个分割出来的子字符串 YY,用由 YY 中包含的字符紧接其后跟上 YY 的长度所组成的新字符串替换 YY
  • 不改变顺序地连接所有替换后的字符串。

例如,字符串 aaabbcccc 被分为 aaabbcccc,分别被替换为 a3b2c4,然后不改变顺序地连接起来,得到结果字符串 a3b2c4。如果给定的字符串是 aaaaaaaaaa,则新字符串为 a10

求满足以下条件的小写英文字母组成长度为 NN 的字符串 SS 的个数,模 PP 后的结果:通过上述过程对字符串 SS 进行操作得到的字符串 TT 的长度小于 SS 的长度。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Consider the following procedure of, given a string XX consisting of lowercase English alphabets, obtaining a new string:

  • Split the string XX off at the positions where two different characters are adjacent to each other.
  • For each string YY that has been split off, replace YY with a string consisting of the character which YY consists of, followed by the length of YY.
  • Concatenate the replaced strings without changing the order.

For example, aaabbcccc is divided into aaa,bb,cccc, which are replaced by a3,b2,c4, respectively, which in turn are concatenated without changing the order, resulting in a3b2c4.If the given string is aaaaaaaaaa , the new string is a10 .

Find the number, modulo PP, of strings SS of lengths NN consisting of lowercase English alphabets, such that the length of TT is smaller than that of SS, where TT is the string obtained by the procedure above against the string SS.

Constraints

  • 1N30001 \le N \le 3000
  • 108P10910^8 \le P \le 10^9
  • NN and PP are integers.
  • PP is a prime.

Input

Input is given from Standard Input in the following format:

NN PP

Output

Print the answer.

Sample Input 1

3 998244353

Sample Output 1

26

Those strings of which the 11-st, 22-nd, and 33-rd characters are all the same satisfy the condition.

For example, aaa becomes a3, which satisfies the condition, while abc becomes a1b1c1, which does not.

Sample Input 2

2 998244353

Sample Output 2

0

Note that if a string is transformed into another string of the same length, such as aa that becomes a2, it does not satisfy the condition.

Sample Input 3

5 998244353

Sample Output 3

2626

Strings like aaabb and aaaaa satisfy the condition.

Sample Input 4

3000 924844033

Sample Output 4

607425699

Find the number of strings satisfying the condition modulo PP.

update @ 2024/3/10 10:39:08