PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000188. Đếm xâu được nén ngắn hơn bằng RLE (RLE)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm xâu được nén ngắn hơn bằng RLE (RLE)

RLE

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

For a lowercase English string SS, split it into maximal consecutive runs of equal characters. Replace a run of character cc repeated ll times by c followed by the decimal representation of ll (including l=1l=1). For instance, aaabbcccc becomes a3b2c4, aaaaaaaaaa becomes a10, and ab becomes a1b1. Given NN and a prime PP, among all 26N26^N original strings of length exactly NN, count those whose encoded length is strictly less than NN, modulo PP. Print the count, not any encoded string.

Input

One line contains integers N,PN,P, where PP is prime.

Output

Print the number of qualifying length-NN strings modulo PP.

Subtasks

  • Subtask 1 (20 points): 1≤N≤101\le N\le10; 108≤P≤10910^8\le P\le10^9, and PP is prime.
  • Subtask 2 (30 points): 1≤N≤6001\le N\le600; 108≤P≤10910^8\le P\le10^9, and PP is prime.
  • Subtask 3 (50 points): 1≤N≤30001\le N\le3000; 108≤P≤10910^8\le P\le10^9, and PP is prime.

Examples

Example 1

Input

3 998244353

Output

26

Explanation

Each run of length ll encodes to one letter plus the decimal length, costing 1+digits(l)1+digits(l) characters. Adjacent runs must have different letters: 26 choices for the first run, 25 for each subsequent run. For N=3N=3, only one run of length 3 compresses from length 3 to a3 of length 2. There are exactly 26 choices for its letter.

Example 2

Input

5 998244353

Output

2626

Explanation

Each run of length ll encodes to one letter plus the decimal length, costing 1+digits(l)1+digits(l) characters. Adjacent runs must have different letters: 26 choices for the first run, 25 for each subsequent run. For N=5N=5: a single run contributes 26 strings; two runs of lengths (1,4), (2,3), (3,2), (4,1) each contribute 26⋅25=65026\cdot25=650. Total 26+4⋅650=262626+4\cdot650=2626.