#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int add (int a, int b) {
	a += b; if (a >= MOD) a -= MOD;
	return a;
}
int sub (int a, int b) {
	a -= b; if (a < 0) a += MOD;
	return a;
}
int mul (int a, int b) {
	return (a * 1ll * b) % MOD;
}
int power (int a, int b) {
	if (!b) return 1;
	int u = power(a, b >> 1);
	u = mul(u, u);
	if (b & 1) u = mul(u, a);
	return u;
}
const int N = 5000;
int fact[N + 1], inv[N + 1];
int nCr (int a, int b) {
	return mul(fact[a], mul(inv[b], inv[a - b]));
}
int pw4[N + 1], ff[N + 1];
int ans2 (int w, int h) {
	int ret = 0;
	for (int x = 0; x <= min(w / 2, h); x++) {
		for (int y = 0; y <= min(h / 2, w); y++) {
			if (2 * x + y <= w && 2 * y + x <= h) {
				int s = 1;
				s = mul(s, nCr(w, 2 * x));
				s = mul(s, nCr(w - 2 * x, y));
				s = mul(s, nCr(h, 2 * y));
				s = mul(s, nCr(h - 2 * y, x));
				s = mul(s, fact[x]);
				s = mul(s, fact[y]);
				s = mul(s, ff[2 * x]);
				s = mul(s, ff[2 * y]);
				ret = add(ret, s);
			}
		}
	}
	return ret;
}
int ans (int a, int b) {
	int ret = 0;
	for (int i = 0; i <= min(a, b); i++) {
		ret = add(ret, mul(pw4[i], mul(nCr(a, i), mul(nCr(b, i), mul(fact[i], ans2(a - i, b - i))))));
	}
	return ret;
}
void solve () {
	fact[0] = 1;
	for (int i = 1; i <= N; i++) {
		fact[i] = mul(i, fact[i - 1]);
	}
	inv[N] = power(fact[N], MOD - 2);
	for (int i = N - 1; i >= 0; i--) {
		inv[i] = mul(i + 1, inv[i + 1]);
	}
	pw4[0] = 1;
	for (int i = 1; i <= N; i++) {
		pw4[i] = mul(4, pw4[i - 1]);
	}
	ff[0] = 1;
	for (int i = 2; i <= N; i += 2) {
		ff[i] = mul(i - 1, ff[i - 2]);
	}
	int h, w; cin >> h >> w;
	cout << sub(ans(h, w), 1) << '\n';
}
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	int tc = 1; //cin >> tc;
	while (tc--) solve();
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |