local mod = 998244353 local mfl = math.floor local function bmul(x, y) local x0, y0 = x % 31596, y % 31596 local x1, y1 = mfl(x / 31596), mfl(y / 31596) return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod end local function badd(x, y) return (x + y) % mod end local function bsub(x, y) return x < y and x - y + mod or x - y end local function modpow(src, pow) local res = 1 while 0 < pow do if pow % 2 == 1 then res = bmul(res, src) pow = pow - 1 end src = bmul(src, src) pow = mfl(pow / 2) end return res end local function modinv(src) return modpow(src, mod - 2) end --[[ !! (for Multiple) y1 1 0 0 0 1 0 x1 y2 1 2 0 1 1 0 x2 y3 = 1/6 * 1 0 2 0 1 0 * x3 y4 1 1 0 2 1 0 x4 y5 1 0 0 0 1 0 x5 y0 1 1 1 1 1 1 x0 ]] local pw, pos = io.read("*n", "*n") local n = 6 if pos == 0 then pos = 6 end local tmpmat = {} local mat = {} for i = 1, n do tmpmat[i] = {} mat[i] = {1, 1, 1, 1, 1, 1} end local vec = {0, 0, 0, 0, 0, 1} local tmpvec = {} local function matmat() for i = 1, n do for j = 1, n do local v = 0 for k = 1, n do v = badd(v, bmul(mat[i][k], mat[k][j])) end tmpmat[i][j] = v end end for i = 1, n do for j = 1, n do mat[i][j] = tmpmat[i][j] end end end local function matvec() for i = 1, n do local v = 0 for k = 1, n do v = badd(v, bmul(mat[i][k], vec[k])) end tmpvec[i] = v end for i = 1, n do vec[i] = tmpvec[i] end end local nn = pw while true do if nn % 2 == 1 then matvec() nn= nn - 1 end if nn == 0 then break end nn = mfl(nn / 2) matmat() end local denom = modinv(modpow(6, pw)) print(bmul(denom, vec[pos]))