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
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
int n,mod,jc[6010],iv[6010];
int dp[6010][12010],tmp,d2,ans;
void update(int &x,int y) { x+=y; if (x>=mod) x-=mod; }
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(mod);
	jc[0]=iv[0]=jc[1]=iv[1]=1;
	for (int i=2;i<=n*3;i++) {
		jc[i]=(ll)jc[i-1]*i%mod;
		iv[i]=(ll)(mod-mod/i)*iv[mod%i]%mod;
	}
	dp[0][0]=1;
	for (int s=0;s<n*3;s++)
	for (int d=-s;d<=s;d++) {
		if (!dp[s][d]) continue;
		for (int i=1;i<=3;i++) {
			if (s+i>n*3) continue;
			d2=d;
			if (i==1) d2++;
			if (i==2) d2--;
			if (-(s+i)<=d2&&d2<=s+i) {
				tmp=(ll)dp[s][d]*iv[s+i]%mod;
				update(dp[s+i][d2],tmp);
			}
		}
	}
	for (int d=0;d<=n*3;d++) update(ans,dp[n*3][d]);
	printf("%d\n",(ll)ans*jc[n*3]%mod);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/