import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.lang.AssertionError import java.util.* import kotlin.math.abs import kotlin.math.max import kotlin.math.min val MOD = 998244353L class LinearFunctionCompositionMod(val N: Int, val MOD: Long) { private val c0 = LongArray(N) private val c1 = LongArray(N) /** * [l, r) * @param s f(l)の値 */ fun add(l: Int, r: Int, delta: Long, s: Long) { val d1 = if (delta >= 0) delta else delta + MOD c1[l] += d1 if (c1[l] >= MOD) c1[l] -= MOD c1[r] -= d1 if (c1[r] < 0) c1[r] += MOD var d0 = (s - l*d1%MOD) if (d0 < 0) d0 += MOD c0[l] += d0 if (c0[l] >= MOD) c0[l] -= MOD c0[r] -= d0 if (c0[r] < 0) c0[r] += MOD } fun build() { for (i in 0 until N - 1) { c0[i + 1] += c0[i] if (c0[i + 1] >= MOD) c0[i + 1] -= MOD c1[i + 1] += c1[i] if (c1[i + 1] >= MOD) c1[i + 1] -= MOD } } fun calc(x: Int): Long { return (c1[x] * x + c0[x])%MOD } fun reset() { Arrays.fill(c0, 0) Arrays.fill(c1, 0) } fun reset(other: LinearFunctionCompositionMod) { other.c0.copyInto(c0) other.c1.copyInto(c1) } fun inspect() = Pair(c0, c1) } class Solver(stream: InputStream, private val out: java.io.PrintWriter) { private val reader = BufferedReader(InputStreamReader(stream), 32768) fun solve() { val (N, K) = na(2) val dp1_cur = Array(K + 1){LinearFunctionCompositionMod(K + 1, MOD)} // 組み合わせ val dp1_next = Array(K + 1){LinearFunctionCompositionMod(K + 1, MOD)} // 組み合わせ val dp2_cur = Array(K + 1){LinearFunctionCompositionMod(K + 1, MOD)} val dp2_next = Array(K + 1){LinearFunctionCompositionMod(K + 1, MOD)} for (k1 in 0 until K) { if (k1 > 0) { dp1_cur[k1].add(0, k1, 0, 1) dp2_cur[k1].add(0, k1, 1, 0) dp2_cur[k1].add(0, k1, 0, k1.toLong()) } if (k1 < K - 1) { dp1_cur[k1].add(k1 + 1, K, 0, 1) dp2_cur[k1].add(k1 + 1, K, 1, (k1+1).toLong()) dp2_cur[k1].add(k1 + 1, K, 0, k1.toLong()) } dp1_cur[k1].build() dp2_cur[k1].build() } // if (isDebug) { // debug{"${(0 until K).map{dp1_cur[0].calc(it)}.joinToString(" ")}"} // } for (i in 2 until N) { for (k1 in 0 until K) { for (k2 in 0 until K) { if (k1 == k2) continue val comb = dp1_cur[k1].calc(k2) val c2 = dp2_cur[k1].calc(k2) if (k1 > k2) { dp1_next[k2].add(k2 + 1, k1, 0, comb) dp1_next[k2].add(k1 + 1, K, 0, comb) dp2_next[k2].add(k2 + 1, k1, comb, comb*(k2+1)%MOD) dp2_next[k2].add(k1 + 1, K, comb, comb*(k1 + 1)%MOD) dp2_next[k2].add(k2 + 1, k1, 0, c2) dp2_next[k2].add(k1 + 1, K, 0, c2) } else { dp1_next[k2].add(0, k1, 0, comb) dp1_next[k2].add(k1 + 1, k2, 0, comb) dp2_next[k2].add(0, k1, comb, 0) dp2_next[k2].add(k1 + 1, k2, comb, comb*(k1 + 1)%MOD) dp2_next[k2].add(0, k1, 0, c2) dp2_next[k2].add(k1 + 1, k2, 0, c2) } } } for (k1 in 0 until K) { dp1_next[k1].build() dp1_cur[k1].reset(dp1_next[k1]) dp1_next[k1].reset() dp2_next[k1].build() dp2_cur[k1].reset(dp2_next[k1]) dp2_next[k1].reset() } } if (isDebug) { debug{"${(0 until K).map{dp2_cur[2].calc(it)}.joinToString(" ")}"} } var ans1 = 0L var ans2 = 0L for (k1 in 0 until K) { for (k2 in 0 until K) { ans1 += dp1_cur[k1].calc(k2) ans2 += dp2_cur[k1].calc(k2) } } ans1 %= MOD ans2 %= MOD out.println("$ans1 $ans2") } private val isDebug = try { // なんか本番でエラーでる System.getenv("MY_DEBUG") != null } catch (t: Throwable) { false } private var tokenizer: StringTokenizer? = null private fun next(): String { while (tokenizer == null || !tokenizer!!.hasMoreTokens()) { tokenizer = StringTokenizer(reader.readLine()) } return tokenizer!!.nextToken() } private fun ni() = next().toInt() private fun nl() = next().toLong() private fun ns() = next() private fun na(n: Int, offset: Int = 0): IntArray { return IntArray(n) { ni() + offset } } private fun nal(n: Int, offset: Int = 0): LongArray { val res = LongArray(n) for (i in 0 until n) { res[i] = nl() + offset } return res } private fun na2(n: Int, offset: Int = 0): Array { val a = Array(2){IntArray(n)} for (i in 0 until n) { for (e in a) { e[i] = ni() + offset } } return a } private inline fun debug(msg: () -> String) { if (isDebug) System.err.println(msg()) } /** * コーナーケースでエラー出たりするので、debug(dp[1])のように添え字付きの場合はdebug{}をつかうこと */ private inline fun debug(a: LongArray) { debug { a.joinToString(" ") } } private inline fun debug(a: IntArray) { debug { a.joinToString(" ") } } private inline fun debug(a: BooleanArray) { debug { toString(a) } } private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")} private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } /** * 勝手にimport消されるのを防ぎたい */ private fun hoge() { min(1, 2) max(1, 2) abs(-10) } private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()} private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())} } fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() }