Ascent Sequences

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Consider a sequence a_1,a_2,,a_n\langle a\_1, a\_2, \ldots, a\_n \rangle of non-negative integers. An ascent in the sequence is a pair of adjacent elements such that the element with greater index has greater value. For example, there are two ascents in sequence 0,2,3,1,0\langle 0, 2, 3, 1, 0 \rangle: a_1=0a\_1 = 0 to a_2=2a\_2 = 2, and a_2=2a\_2 = 2 to a_3=3a\_3 = 3. Let us denote the number of ascents among the first kk elements of the sequence by A_kA\_k. In the given example, A_1=0A\_1 = 0, A_2=1A\_2 = 1, A_3=2A\_3 = 2, A_4=2A\_4 = 2 and A_5=2A\_5 = 2.

Sequence aa is called an ascent sequence if a_1=0a\_1 = 0 and for every i2i \ge 2 inequality a_iA_i1+1a\_i \le A\_{i-1} + 1 is satisfied. For example, sequence 0,2,3,1,0\langle 0, 2, 3, 1, 0 \rangle is not an ascent sequence because a_2=2a\_2 = 2 and A_1=0A\_1 = 0. Sequence 0,1,0,2,3\langle 0, 1, 0, 2, 3 \rangle is, in turn, an ascent sequence because A_1=0A\_1 = 0, A_2=1A\_2 = 1, A_3=1A\_3 = 1, A_4=2A\_4 = 2.

Sequence a_1,a_2,,a_n\langle a\_1, a\_2, \ldots, a\_n \rangle of non-negative integers avoids pattern 201 if there are no ii, jj and kk such that i<j<ki < j < k and a_j<a_k<a_ia\_j < a\_k < a\_i. For example, sequence 0,1,0,2,3\langle 0, 1, 0, 2, 3 \rangle avoids pattern 201, while 0,1,2,3,1,0,2\langle 0, 1, 2, 3, 1, 0, 2 \rangle does not avoid pattern 201 because for i=4i = 4, j=6j = 6, k=7k = 7 we have a_j=0<a_k=2<a_i=3a\_j = 0 < a\_k = 2 < a\_i = 3.

You are given two integers nn and pp. Find the number of ascent sequences of length nn avoiding pattern 201, and output this number modulo pp.

입력

The only line of the input contains two integers nn and pp (1n5001 \le n \le 500; 2p109+1232 \le p \le 10^9 + 123; pp is a prime).

출력

Output a single integer --- the number of ascent sequences of length nn avoiding pattern 201, modulo pp.

힌트

In the first example test case, there are five ascent sequences of length 3 avoiding pattern 201: 0,0,0\langle 0, 0, 0 \rangle, 0,0,1\langle 0, 0, 1 \rangle, 0,1,0\langle 0, 1, 0 \rangle, 0,1,1\langle 0, 1, 1 \rangle, 0,1,2\langle 0, 1, 2 \rangle.

In the second example test case, there are 53 ascent sequences of length 5 and all of them except 0,1,2,0,1\langle 0, 1, 2, 0, 1 \rangle avoid pattern 201.