#agc043d. [agc043_d]Merge Triplets

[agc043_d]Merge Triplets

Problem Statement

Given is a positive integer NN. Find the number of permutations (P1,P2,cdots,P3N)(P_1,P_2,\\cdots,P_{3N}) of (1,2,cdots,3N)(1,2,\\cdots,3N) that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number MM.

  • Make NN sequences A1,A2,cdots,ANA_1,A_2,\\cdots,A_N of length 33 each, using each of the integers 11 through 3N3N exactly once.
  • Let PP be an empty sequence, and do the following operation 3N3N times.
    • Among the elements that are at the beginning of one of the sequences AiA_i that is non-empty, let the smallest be xx.
    • Remove xx from the sequence, and add xx at the end of PP.

Constraints

  • 1leqNleq20001 \\leq N \\leq 2000
  • 108leqMleq109+710^8 \\leq M \\leq 10^9+7
  • MM is a prime number.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

Output

Print the number of permutations modulo MM.


Sample Input 1

1 998244353

Sample Output 1

6

All permutations of length 33 count.


Sample Input 2

2 998244353

Sample Output 2

261

Sample Input 3

314 1000000007

Sample Output 3

182908545