#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define debug(x) cout << #x << " = " << x << '\n'
#define all(a) a.begin(), a.end()
#define SZ(a) (int)(a).size()
const int N = 3e2 + 5;
const int mod = 1e9 + 7;
const ll inf64 = 3e18;
const int inf32 = 2e9 + 5;
ll add(ll a, ll b) {
    a += b;
    if(a < 0) a += mod;
    if(a >= mod) a -= mod;
    return a;
}
ll mul(ll a, ll b) { return a * b % mod; }
int n, m;
ll dp[N][N][N], pw4[N];
void solve() {
    cin >> n >> m;
    pw4[0] = 1;
    for(int i = 1; i <= m; i++) 
        pw4[i] = mul(pw4[i - 1], 4);
    dp[1][0][0] = 1;
    dp[1][1][0] = m;
    dp[1][0][2] = m * (m - 1) / 2;
    for(int i = 1; i < n; i++) {
        for(int open = 0; open <= m; open++) {
            for(int close = 0; close + open <= m; close++) {
                dp[i + 1][open][close] = add(dp[i + 1][open][close], dp[i][open][close]);
                // dat vao dong i+1 1 cai leu
                // dat vao o trong -> open+1
                if(open + close + 1 <= m) {
                    dp[i + 1][open + 1][close] = add(dp[i + 1][open + 1][close], mul(dp[i][open][close], m - open - close));
                }
                // dat vao o open -> open-1, close+1
                if(open - 1 >= 0 && close + 1 <= m) {
                    dp[i + 1][open - 1][close + 1] = add(dp[i + 1][open - 1][close + 1], mul(dp[i][open][close], open));
                }
                
                // dat vao dong i+1 2 cai leu 
                // chi dat vao cac o trong -> close + 2
                if(open + close + 2 <= m) {
                    ll tmp = (m - open - close) * (m - open - close - 1) / 2;
                    dp[i + 1][open][close + 2] = add(dp[i + 1][open][close + 2], mul(dp[i][open][close], tmp)); 
                }
            }
        }
    }
    ll ans = 0;
    for(int open = 0; open <= m; open++) {
        for(int close = 0; close <= m && open + close <= m; close++) 
            ans = add(ans, mul(dp[n][open][close], pw4[open]));
    }
    cout << add(ans, -1) << '\n';
}
int main() {
    auto start = chrono::steady_clock::now();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    int test = 1; 
    // cin >> test;
    while(test--) solve();
    
    chrono::duration<double> elapsed {chrono::steady_clock::now() - start};
    cerr << "\n>> Runtime: " << elapsed.count() << "s\n";
}
컴파일 시 표준 에러 (stderr) 메시지
tents.cpp: In function 'int main()':
tents.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |