MOD = 998244353i64 def inv(v : Int64) pow(v, MOD - 2) end def pow(v : Int64, p) ret = 1i64 while p > 0 if (p & 1i64) != 0 ret *= v ret %= MOD end v *= v v %= MOD p >>= 1 end ret end n = read_line.to_i64 inv5 = inv(5i64) inv3 = inv(3i64) inv2 = inv(2i64) dp0 = [0i64, inv5 * 2, inv5] # 横、斜め、縦 dp1 = Array.new(3, 0i64) prob0 = [inv5 * 2, inv5 * 2, inv5] prob1 = Array.new(3, 0i64) (n - 1).times do dp1.fill(0i64) prob1.fill(0i64) dp1[0] = dp0[0] * inv2 + dp0[1] * inv3 dp1[1] = (dp0[0] + prob0[0]) * inv2 + (dp0[1] + prob0[1]) * inv3 + (dp0[2] + prob0[2]) * inv3 * 2 dp1[2] = (dp0[1] + prob0[1]) * inv3 + (dp0[2] + prob0[2]) * inv3 prob1[0] = prob0[0] * inv2 + prob0[1] * inv3 prob1[1] = prob0[0] * inv2 + prob0[1] * inv3 + prob0[2] * inv3 * 2 prob1[2] = prob0[1] * inv3 + prob0[2] * inv3 dp1.map! { |v| v % MOD } prob1.map! { |v| v % MOD } dp0, dp1 = dp1, dp0 prob0, prob1 = prob1, prob0 end puts dp0.sum % MOD