#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint1000000007; using T = tuple; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } template class Compress{ public: vector data; int offset; Compress(vector data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; int k, n; mint memo[100005][3][2][2]; bool ok[100005][3][2][2]; T nx(int a, int b, int x){ vector v; if(a != 0) v.push_back(a); if(b != 0) v.push_back(b); if(x != 0) v.push_back(x); auto cp = Compress(v, 1); sort(v.begin(), v.end(), greater()); int m = cp.size(); vector ans(3); for(int i = 0; i < v.size(); i++){ ans[i] = cp[v[i]]; } // cout << "=============" << endl; // cout << a << ' ' << b << ' ' << x << endl; // print_vector(v); // print_vector(ans); return {ans[0], ans[1], ans[2]}; } mint solve(int k, int a, int b, int c){ assert(k != 0); if(k == 1){ return mint(n-a); } if(ok[k][a][b][c]) return memo[k][a][b][c]; mint ans = 0; assert(b <= a); assert(c <= b); for(int x = 1; x <= 4; x++){ if(x >= a+2) continue; vector> vv = { {a, b}, {b, c}, {c, a}, }; mint pat = [&](){ if(x <= a) return mint(1); else return mint(max(0, n-a)); }(); mint tmp = pat; for(auto v: vv){ int a = v[0]; int b = v[1]; auto [aa, bb, cc] = nx(a, b, x); tmp *= solve(k-1, aa, bb, cc); } ans += tmp; } ok[k][a][b][c] = true; memo[k][a][b][c] = ans; return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> k >> n; cout << solve(k+1, 0, 0, 0) << endl; }