#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int n, m, f; ll res1, res2, res3, res4, _, ans1;
inline int qpow(ll x, int y) {
ll t = 1;
for (; y; y>>=1) {
if (y & 1) t = t * x % MOD;
x = x * x % MOD;
} return t;
}
int main() {
// freopen ("game.in", "r", stdin);
// freopen ("game.out", "w", stdout);
cin >> n >> m;
if (n > m) swap(n, m);
if (n == 1) return printf ("%d\n", qpow(2, m)), 0;
if (n == 2) return printf ("%lld\n", 12ll * qpow(3, m - 2) % MOD), 0;
if (n == 3) return printf ("%lld\n", 112ll * qpow(3, m - 3) % MOD), 0;
for (int i=2; i<=n-3; i++) f = (4ll * f + 20) % MOD;
res2 = qpow(2, 3 * n - 7), res1 = 16ll * res2 % MOD, res2 = 5ll * res2 % MOD;
_ = qpow(2, n), ans1 = _ * (2 * f + 15) % MOD;
if (n == m) return printf ("%lld\n", (res1 + res2 + ans1) % MOD), 0;
res3 = _ * (3ll * f + 20) % MOD, res4 = _ * (3ll * f + 22) % MOD;
return printf ("%lld\n", ((res1 + res2) * 3 + res3 + res4) * qpow(3, m - n - 1) % MOD), 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 34.34 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 44.18 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 36.59 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 35.1 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 34.58 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 35.35 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 35.02 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 34.48 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 34.56 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 34.33 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 35.03 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 34.86 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 34.68 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 34.8 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 35.42 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 34.96 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 43.61 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 34.61 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 36.42 us | 36 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 33.8 us | 36 KB | Accepted | Score: 5 | 显示更多 |