#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define all(a) (a).begin(), (a).end() #define contains(a, x) ((a).find(x) != (a).end()) #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--) #define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n"); #define YN(b) cout << ((b) ? "YES" : "NO") << "\n"; #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define yn(b) cout << ((b) ? "yes" : "no") << "\n"; using ll = long long; using vi = vector; using vvi = vector; using vl = vector; using mint = modint998244353; using vm = vector; template class Factorial { public: Factorial(int max) : n(max) { f = std::vector(n + 1); finv = std::vector(n + 1); f[0] = 1; for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i; finv[n] = f[n].inv(); for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * i; } mint fact(int k) const { assert(0 <= k && k <= n); return f[k]; } mint fact_inv(int k) const { assert(0 <= k && k <= n); return finv[k]; } mint binom(int k, int r) const { assert(0 <= k && k <= n); if (r < 0 || r > k) return 0; return f[k] * finv[r] * finv[k - r]; } mint inv(int k) const { assert(0 < k && k <= n); return finv[k] * f[k - 1]; } private: int n; std::vector f, finv; }; using ar = array; ar mul(ar a, ar b) { ar r{0, 0, 0}; rep(i, 0, 3) rep(j, 0, 3) r[(i + j) % 3] += a[i] * b[j]; return r; } ar pow(ar a, int n) { ar r{1, 0, 0}; while (n) { if (n & 1) r = mul(r, a); a = mul(a, a); n /= 2; } return r; } void solve() { int n, m; cin >> n >> m; Factorial fact(m); mint ans = 0; rep(a, 0, m + 1) rep(b, 0, m + 1 - a) { int c = m - a - b; ar v{0, 0, 0}; int d = (2 * b + c) % 3; v[d] = fact.fact_inv(a) * fact.fact_inv(b) * fact.fact_inv(c); v = mul(v, pow(ar{a, b, c}, n)); ans += v[0] - v[2]; } ans *= fact.fact(m); ans /= mint(3).pow(m); cout << ans.val() << endl; } int main() { int t = 1; // cin >> t; while (t--) solve(); }