p02036 Donuts Orientation_32109
G: Donuts Orientation

story

Homu-chan's recent boom is making sweets. It seems that he makes a lot of sweets and shares them with his friends. Homu-chan seems to be trying to make donuts this time.

There are many important things in making donuts. Not only the dough and seasoning, but also the decorations to make it look cute. Through repeated trial and error, it seems that Homu-chan's commitment to decoration has become enthusiastic. Homu-chan wants to make a lot of donuts because he wants many people to eat the donuts that he has been particular about.

By the way, it doesn't matter if you stick to it, but is it possible to prepare a sufficient number of donuts that Homu-chan is particular about?

problem

For integers N greater than or equal to 3, create a graph of 2N vertices as follows.

* Number each vertex from 1 to 2N.
* For each integer 1 \ leq a \ leq N, put an undirected edge between vertices 2a-1 and 2a.
* For each integer 1 \ leq b \ leq 2N-2, put an undirected edge between vertices b and b + 2.
* Extend an undirected edge between vertices 1 and 2N-1 and 2 and 2N



Make a directed graph by orienting each side of this graph. That is, if there is an undirected edge between the vertices u and v, make it a directed edge from u to v or a directed edge from v to u.

I would like to know how many directed graphs created in this way do not have a cycle. The answer is very large, so find the remainder after dividing by the prime number M.

Input format


N M

Constraint

* 3 \ leq N \ leq 1,000
* 10 ^ 8 \ leq M \ leq 10 ^ 9 + 7
* M is guaranteed to be prime



Output format

Output the remainder of dividing the number of directed graphs that satisfy the condition by M.

Input example 1


3 1000000007

Output example 1


204

Since N = 3, we make a graph with 6 vertices. An example of a directed graph that meets the conditions is as follows.

Due to the existence of cycles, the directed graph shown below does not meet the condition.

Input example 2


128 998244353

Output example 2


996915100

Note that the remainder after dividing by M is output.





Example

Input

3 1000000007


Output

204
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
//const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,mod;
vi dp(4096);

int main(){
	cin>>n>>mod;
	for(int j=0;j<4096;j++){
		int a=j%2,b=j/2%2,c=j/4%2,d=j/8%2,e=j/16%2,f=j/32%2,g=j/64%2,h=j/128%2,x=j/256%2,y=j/512%2,z=j/1024%2,t=j/2048%2;
		if(x!=t) continue;
		if(x==0&&a==1&&b==1&&c==0&&d==1&&e==1&&f==0&&g==1&&h==1) dp[j]++;
		if(x==1&&a==1&&b==0&&c==1&&d==1&&e==1&&f==1&&g==0&&h==1) dp[j]++;
	}
	for(int i=1;i<n;i++){
		vi DP(4096);
		for(int j=0;j<4096;j++) for(int k=0;k<8;k++){
			int a=j%2,b=j/2%2,c=j/4%2,d=j/8%2,e=j/16%2,f=j/32%2,g=j/64%2,h=j/128%2,x=j/256%2,y=j/512%2,z=j/1024%2,t=j/2048%2;
			int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,X=k%2,Y=k/2%2,Z=k/4%2;
			if(x==0&&y==0&&z==0&&X==1||x==1&&y==1&&z==1&&X==0) continue;
			if(a==1&&y==1) A=1;
			if(b==1&&z==0) B=1;
			if(A==1&&X==0) B=1;
			if(B==1&&X==1) A=1;
			if(c==1&&y==1) C=1;
			if(d==1&&z==0) D=1;
			if(C==1&&X==0) D=1;
			if(D==1&&X==1) C=1;
			if(e==1&&y==0) E=1;
			if(f==1&&z==1) F=1;
			if(E==1&&X==1) F=1;
			if(F==1&&X==0) E=1;
			if(g==1&&y==0) G=1;
			if(h==1&&z==1) H=1;
			if(G==1&&X==1) H=1;
			if(H==1&&X==0) G=1;
			if(i==n-1){
				if(A==1&&Y==1||B==1&&Z==0&&t==1) continue;
				if(D==1&&Z==0||C==1&&Y==1&&t==0) continue;
				if(E==1&&Y==0||F==1&&Z==1&&t==0) continue;
				if(H==1&&Z==1||G==1&&Y==0&&t==1) continue;
				if(X==0&&Y==0&&Z==0&&t==1) continue;
				if(X==1&&Y==1&&Z==1&&t==0) continue;
			}
			(DP[A+B*2+C*4+D*8+E*16+F*32+G*64+H*128+X*256+Y*512+Z*1024+t*2048]+=dp[j])%=mod;
		}
		dp=DP;
	}
	int res=0;
	for(auto i:dp) (res+=i)%=mod;
	cout<<res<<endl;
}
