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

* Make N sequences A_1,A_2,\cdots,A_N of length 3 each, using each of the integers 1 through 3N exactly once.
* Let P be an empty sequence, and do the following operation 3N times.
* Among the elements that are at the beginning of one of the sequences A_i that is non-empty, let the smallest be x.
* Remove x from the sequence, and add x at the end of P.

Constraints

* 1 \leq N \leq 2000
* 10^8 \leq M \leq 10^9+7
* M is a prime number.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N M


Output

Print the number of permutations modulo M.

Examples

Input

1 998244353


Output

6


Input

2 998244353


Output

261


Input

314 1000000007


Output

182908545
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=6023,M=12023};

ll f[4][M*2];

int main(){
	int n=ci(), mod=ci();
	f[0][N+0] = 1;
	f[1][N+1] = 1;
	f[2][N-1] = 1;
	f[2][N+2] = 1;
	rep(i,3,n*3){
		int I = i&3;
		rep(j,-i/2,i){
			f[I][N+j] = (f[(i-1)&3][N+j-1] 
					+ (i-1)*f[(i-2)&3][N+j+1]
					+ 1ll*(i-1)*(i-2)*f[(i-3)&3][N+j] ) %mod ;
		}
	}
	ll ans = 0;
	rep(i,0,n) ans=(ans+f[(n*3)&3][N+i*3])%mod;
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}
