#include #define rep(i,n) for (int i = 0; i < (n); ++i) #define repp(i,n,m) for (int i = m; i < (n); ++i) using namespace std; using ll = long long; using P = pair; using PI = pair,int>; const long long modl = 1000000007LL; struct unionfind { vector d; unionfind(int n=0): d(n,-1) {} int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x,y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y);} int size(int x) { return -d[find(x)];} }; int num(vector a){ a.emplace_back(0); int n = a.size(); int ans = 0; int ima = 0; rep(i,n){ if (a[i] == 0){ if (ima == 1) ans++; ima = 0; } else { ima = 1; } } return ans; } vector nul(vector &a, vector &b){ vector ans(a.size()); int ima = 0; int cnt = 0; rep(i,a.size()){ if (a[i] == 0){ ans[i] = 0; if (ima == 1) cnt++; ima = 0; } else { ans[i] = b[cnt]; ima = 1; } } return ans; } vector iro(vector &a, vector &b){ int n = a.size(); vector ans(n,0); int ma = 0; rep(i,n) ma = max(ma,a[i]); vector> ar(ma,vector(0)); vector ok(ma,false); rep(i,n){ if (a[i] != 0){ if (b[i] == 1) ok[a[i]-1] = true; ar[a[i]-1].emplace_back(i); } } rep(i,ma) if (!ok[i]) return ans; unionfind tree(n); repp(i,n,1){ if (b[i-1] == 1 && b[i] == 1) tree.unite(i-1,i); } rep(i,ma){ auto &r = ar[i]; repp(j,r.size(),1) tree.unite(r[0],r[j]); } int ima = 1; map mp; rep(i,n){ if (b[i] == 0) ans[i] = 0; else { int ne = tree.find(i); if (mp.find(ne) == mp.end()){ mp[ne] = ima; ans[i] = ima; ima++; } else { ans[i] = mp[ne]; } } } return ans; } struct dat{ set s; stack st; vector an; set stin; int ima; }; set ::iterator ite;; vector> komo(int n){ vector> ans(0,vector(n)); queue que; dat a; a.ima = 2; a.s.insert(1); que.push(a); while (!que.empty()){ dat q = que.front(); que.pop(); if (q.an.size() == n){ ans.emplace_back(q.an); continue; } for (ite = q.s.begin(); ite != q.s.end(); ite++){ dat p = q; int m = *ite; if (p.stin.find(m) == p.stin.end()){ p.an.emplace_back(m); p.stin.insert(m); p.st.push(m); if (m == p.ima -1){ p.s.insert(p.ima); p.ima++; } } else { p.an.emplace_back(m); int col = p.st.top(); while (col != m){ p.s.erase(col); p.st.pop(); col = p.st.top(); } } que.push(p); } } return ans; } bool chan(vector &a){ int ma = 0; vector si = a; rep(i,a.size()) { ma = max(ma,a[i]); if (a[i] == 0) si[i] = 0; else si[i] = 1; } return ma == num(si); } vector tugi(vector> &mat, vector ima){ vector ans(ima.size(),0LL); rep(i,ima.size()){ rep(j,ima.size()){ ans[i] += mat[i][j] * ima[j]; ans[i] %= modl; } } return ans; } vector mnpoly(vector> &mnp, vector &truepoly){ vector ans(mnp.size(),0LL); rep(i,mnp.size()){ rep(j,truepoly.size()){ ans[i] += mnp[i][truepoly[j]]; } } return ans; } int main() { int m, n; cin >> m >> n; int ni = 1<> ar(1<(m)); repp(i,1<> j & 1) ar[i][j] = 1; else ar[i][j] = 0; } } vector>> col((m+3)/2,vector>(0,vector(0))); repp(i,(m+3)/2,1) col[i] = komo(i); vector> ans; rep(i,ar.size()){ int a = num(ar[i]); rep(j,col[a].size()){ auto b = ar[i]; ans.emplace_back(nul(b,col[a][j])); } } int zen = ans.size(); map,int> mp; rep(i,zen){ mp[ans[i]] = i; } vector> mat(zen,vector(zen,0LL)); vector tan(m,0); rep(i,zen){ repp(j,ni,1){ auto x = iro(ans[i],ar[j]); if (x == tan) continue; int ind = mp[x]; mat[ind][i] += 1LL; } } vector> mnp(1,vector(zen)); rep(i,zen){ if (chan(ans[i])) mnp[0][i] = 1LL; else mnp[0][i] = 0LL; } rep(i,n){ auto a = mnp[i]; auto b = tugi(mat,a); mnp.emplace_back(b); } vector truepoly; rep(i,zen){ bool t = true; rep(j,m){ if (ans[i][j] > 1) t = false; } if (t) truepoly.emplace_back(i); } auto kai = mnpoly(mnp,truepoly); ll polysum = 0LL; rep(i,n) { polysum += ll(n-i) * kai[i]; polysum %= modl; } cout << polysum << endl; }