#include using namespace std; #define lli long long int #define uli unsigned long long int #define INF 999999999999999999 #define rep(i,m,n) for(lli i = m;i < n;i++) #define rrep(i,m,n) for(lli i=m-1;i>=n;i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(),N.end()),N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(),n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(30) << S << endl #define Vec(K,L,N,S) vector K(N,S) #define DV(K,L,N,M,S) vector> K(N,vector(M,S)) #define TV(K,L,N,M,R,S) vector>> K(N,vector>(M,vector(R,S))) #define pint pair #define paf(L,R) pair #define mod 1000000007 #define MAX 5100000 #define ALL(a) a.begin(),a.end() #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) bool flag(int l,int r){ return (l%5==0)&&(r%5==0); } int main(){ lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0;string S,T; cin>> N >> K ; cin>>A>>B>>C>>D; lli dp[2][5][5][5][5]={}; dp[N][C][D][A][B]=1; rep(i,0,K+1){ rep(l1,0,5)rep(r1,0,5)rep(l2,0,5)rep(r2,0,5){//1:高橋,2:lot if((l1==0&&r1==0)||(l2==0&&r2==0)) continue; auto now=dp[N][l1][r1][l2][r2]; if(N&1){ if(flag(l1+l2,r2)||flag(r1+l2,r2)||flag(l2,l1+r2)||flag(l2,r1+r2))continue; bool marge=0; rep(x,0,5){ lli y=l1+r1-x; if(y<0) continue; y%=5; if(flag(x,y)||flag(x+l2,y)||flag(x+r2,y)||flag(x,y+l2)||flag(x,y+r2))continue; if((y==l1&&x==r1)||(x==l1&&y==r1))continue; marge=1; dp[0][x][y][l2][r2]+=now; dp[0][x][y][l2][r2]%=mod; } bool attack=0; if(l1){ if(!flag(l1+r2,r1)&&!flag(2*l1+l2,r1)){ dp[0][l1][r1][(l1+l2)%5][r2]+=now; dp[0][l1][r1][(l1+l2)%5][r2]%=mod; attack=1; } if(!flag(l1+l2,r1)&&!flag(2*l1+r2,r1)){ dp[0][l1][r1][l2][(l1+l2)%5]+=now; dp[0][l1][r1][l2][(l1+l2)%5]%=mod; attack=1; } } if(r1){ if(!flag(l1,r1+r2)&&!flag(l1,2*r1+l2)){ dp[0][l1][r1][(r1+l2)%5][r2]+=now; dp[0][l1][r1][(r1+l2)%5][r2]%=mod; attack=1; } if(!flag(l1,r1+l2)&&!flag(l1,2*r1+r2)){ dp[0][l1][r1][l2][(r1+r2)%5]+=now; dp[0][l1][r1][l2][(r1+r2)%5]%=mod; attack=1; } } if(!marge&&!attack){ if(l1){ dp[0][l1][r1][(l1+l2)%5][r2]+=now; dp[0][l1][r1][(l1+l2)%5][r2]%=mod; dp[0][l1][r1][l2][(l1+r2)%5]+=now; dp[0][l1][r1][l2][(l1+r2)%5]%=mod; } if(r1){ dp[0][l1][r1][(r1+l2)%5][r2]+=now; dp[0][l1][r1][(r1+l2)%5][r2]%=mod; dp[0][l1][r1][l2][(r1+r2)%5]+=now; dp[0][l1][r1][l2][(r1+r2)%5]%=mod; } } } else{ if(l2){ dp[1][(l1+l2)%5][r1][l2][r2]+=now; dp[1][(l1+l2)%5][r1][l2][r2]%=mod; dp[1][l1][(l2+r1)%5][l2][r2]+=now; dp[1][l1][(l2+r1)%5][l2][r2]%=mod; } if(r2){ dp[1][(l1+r2)%5][l2][r1][r2]+=now; dp[1][(l1+r2)%5][l2][r1][r2]%=mod; dp[1][l1][(r1+r2)%5][l2][r2]+=now; dp[1][l1][(r1+r2)%5][l2][r2]%=mod; } rep(x,0,5){ lli y=l2+r2-x; if(y<0) continue; y%=5; if((x==0&&y==0)||(x==l2&&y==r2)||(y==l2&&x==r2))continue; dp[1][l1][r1][x][y]+=now; dp[1][l1][r1][x][y]%=mod; } } } rep(l1,0,5)rep(r1,0,5)rep(l2,0,5)rep(r2,0,5){ if(l1==r1==0){ sum+=dp[N][l1][r1][l2][r2]; sum%=mod; } dp[N][l1][r1][l2][r2]=0; } N=1-N; } cout<< sum%mod <