@file:Suppress("EXPERIMENTAL_API_USAGE")

import Utils.ArrayUtils.Companion.arrayOfNullsSafe
import Utils.ArrayUtils.Companion.makeDistinct
import Utils.ArrayUtils.Companion.toNotNulls
import Utils.ArrayUtils.Prints.Companion.println
import Utils.ArrayUtils.Sorts.Companion.countSort
import Utils.ArrayUtils.Sorts.Companion.shuffleSort
import Utils.ArrayUtils.Swaps.Companion.swap
import Utils.BinarySearchUtils.Companion.binarySearch
import Utils.BinarySearchUtils.Companion.binarySearchDouble
import Utils.BinarySearchUtils.Companion.binarySearchLong
import Utils.BitUtils.Companion.flip
import Utils.BitUtils.Companion.get
import Utils.BitUtils.Companion.set
import Utils.BitUtils.Companion.submaskOf
import Utils.FastReader
import Utils.GeneralUtils.Companion.catch
import Utils.GeneralUtils.Companion.length
import Utils.GeneralUtils.Companion.rnd
import Utils.MathUtils.Companion.compareDoubles
import Utils.MathUtils.Companion.gcd
import Utils.MathUtils.Companion.log2
import Utils.Pairs.Companion.ComparablePair
import Utils.Pairs.Companion.IntPair
import Utils.Pairs.Companion.LongPair
import java.io.*
import java.util.*
import kotlin.collections.ArrayDeque
import kotlin.math.*
import kotlin.random.Random
import kotlin.time.ExperimentalTime

@ExperimentalStdlibApi
@ExperimentalTime
@ExperimentalUnsignedTypes
fun main() {
    Locale.setDefault(Locale.US)
    System.setOut(PrintStream(BufferedOutputStream(System.out)))
    Task(FastReader()).solve()
    System.out.flush()
}

const val eps = 1e-8

const val mod = 998244353

inline class MInt(val x: Int) {
    operator fun plus(m: MInt) = MInt((x + m.x) % mod)
    operator fun minus(m: MInt) = MInt((x - m.x + mod) % mod)
    operator fun times(m: MInt) = MInt((x.toLong() * m.x % mod).toInt())

    override fun toString() = x.toString()

    companion object {
        private val facts = mutableListOf(1)
        private val invs = mutableListOf(1, 1)
        private val invFacts = mutableListOf(1)
        fun Int.mod() = MInt(this)

        fun factorial(x: Int): MInt {
            while (x !in facts.indices) facts += (facts.last().mod() * facts.size.mod()).x
            return facts[x].mod()
        }

        fun inv(x: Int): MInt {
            while (x !in invs.indices) invs += (MInt((mod - mod / x) % mod) * invs[mod % x].mod()).x
            return invs[x].mod()
        }

        fun invFact(x: Int): MInt {
            while (x !in invFacts.indices) invFacts += (invFacts.last().mod() * inv(invFacts.size)).x
            return invFacts[x].mod()
        }
    }
}

fun c(n: Int, k: Int) = if (k in 0..n) MInt.factorial(n) * MInt.invFact(k) * MInt.invFact(n - k) else MInt(0)

@ExperimentalTime
@ExperimentalStdlibApi
class Task(private val fin: FastReader = FastReader()) {
    fun solve() {
        val n = fin.readInt()
        val maxHealth = fin.readInt()

        val powers = Array(maxHealth + 1) { x ->
            Array(n + 1) { null as MInt? }.apply {
                this[0] = MInt(1)
                for (p in 1 until size) this[p] = this[p - 1]!! * MInt(x)
            } as Array<MInt>
        }

        val cache = Array(n + 1) { IntArray(maxHealth + 1) { -1 } }
        fun go(alive: Int, damageGot: Int): MInt {
            if (alive == 0) return MInt(1)
            if (damageGot > maxHealth) return MInt(0)
            if (alive == 1) return MInt(0)
            cache[alive][damageGot].let { if (it != -1) return MInt(it) }
            var res = go(alive, damageGot + alive - 1)
            for (died in 1..alive) {
                val survived = alive - died
                val minWas = 1 + damageGot
                val maxWas = minOf(alive - 1 + damageGot, maxHealth)
                val numberOfWaysDied = c(alive, died)
                val healthForDied = powers[maxWas - minWas + 1][died]
                res += go(survived, damageGot + alive - 1) * numberOfWaysDied * healthForDied
            }
            cache[alive][damageGot] = res.x
            return res
        }

        val ans = go(n, 0)
        println(ans)
    }
}

@Suppress("MemberVisibilityCanBePrivate", "unused")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
class Utils {
    class GeneralUtils {
        companion object {
            val rnd = Random(239)
            val IntRange.length get() = maxOf(last - first + 1, 0)

            @Suppress("UNREACHABLE_CODE", "ControlFlowWithEmptyBody")
            fun <R> catch(throwMLE: Boolean = false, f: () -> R): R {
                try {
                    return f()
                } catch (e: Exception) {
                    if (throwMLE) throw OutOfMemoryError()
                    while (true) {
                    }
                }
            }
        }
    }

    class MathUtils {
        companion object {
            tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
            tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
            fun lcm(a: Long, b: Long) = a / gcd(a, b) * b

            fun Int.log2(): Int {
                var log = 0
                while (1 shl log < this) log++
                return log
            }

            fun Long.log2(): Int {
                var log = 0
                while (1L shl log < this) log++
                return log
            }

            fun compareDoubles(x: Double, y: Double) =
                if (abs(x - y) < eps) 0 else if (x < y) -1 else +1

            fun isZero(x: Double) = abs(x) < eps
        }
    }

    class BitUtils {
        companion object {
            operator fun Int.get(bit: Int) = (this shr bit) and 1
            operator fun Long.get(bit: Int) = ((this shr bit) and 1).toInt()
            fun Int.set(bit: Int) = this or (1 shl bit)
            fun Long.set(bit: Int) = this or (1L shl bit)
            fun Int.flip(bit: Int) = this xor (1 shl bit)
            fun Long.flip(bit: Int) = this xor (1L shl bit)
            infix fun Int.submaskOf(x: Int) = (this and x) == this
            infix fun Long.submaskOf(x: Long) = (this and x) == this
        }
    }

    class ArrayUtils {
        companion object {
            fun <T : Comparable<T>> MutableList<T>.makeDistinct() {
                if (size <= 1) return
                sort()
                var sz = 1
                for (i in 1 until size) {
                    if (this[i] != this[i - 1]) {
                        this[sz++] = this[i]
                    }
                }
                while (size > sz) removeAt(lastIndex)
            }

            @Suppress("UNCHECKED_CAST")
            fun <T> Array<T?>.toNotNulls() = this as Array<T>

            @Suppress("UNCHECKED_CAST")
            inline fun <reified T> arrayOfNullsSafe(size: Int): Array<T> =
                arrayOfNulls<T>(size).toNotNulls()
        }

        class Swaps {
            companion object {
                fun <T> Array<T>.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                }

                fun <T> MutableList<T>.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                }

                fun IntArray.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                }

                fun LongArray.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                }

                fun DoubleArray.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                    sort()
                }

                fun CharArray.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                    sort()
                }
            }
        }

        class Sorts {
            companion object {
                fun IntArray.shuffleSort() {
                    for (i in 1 until size) swap(i, rnd.nextInt(i + 1))
                    sort()
                }

                fun LongArray.shuffleSort() {
                    for (i in 1 until size) swap(i, rnd.nextInt(i + 1))
                    sort()
                }

                fun DoubleArray.shuffleSort() {
                    for (i in 1 until size) swap(i, rnd.nextInt(i + 1))
                    sort()
                }

                fun CharArray.shuffleSort() {
                    for (i in 1 until size) swap(i, rnd.nextInt(i + 1))
                    sort()
                }

                @Suppress("DuplicatedCode")
                inline fun <reified T> Array<T>.countSort(
                    inPlace: Boolean = true,
                    type: (T) -> Int = { (it as Number).toInt() }
                ): Array<T> {
                    if (isEmpty()) return if (inPlace) this else emptyArray()
                    val types = IntArray(size) { type(this[it]) }
                    val min = types.minOrNull()!!
                    val max = types.maxOrNull()!!
                    val count = IntArray(max - min + 1)
                    for (t in types) count[t - min]++
                    var sum = 0
                    for (i in count.indices) {
                        val shift = count[i]
                        count[i] = sum
                        sum += shift
                    }
                    val sorted = arrayOfNullsSafe<T>(size)
                    for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]
                    return if (inPlace) {
                        this.also { sorted.copyInto(this) }
                    } else {
                        sorted
                    }
                }

                @Suppress("DuplicatedCode")
                inline fun <reified T> List<T>.countSort(
                    inPlace: Boolean = true,
                    type: (T) -> Int = { (it as Number).toInt() }
                ): List<T> {
                    if (isEmpty()) return if (inPlace) this else emptyList()
                    val types = IntArray(size) { type(this[it]) }
                    val min = types.minOrNull()!!
                    val max = types.maxOrNull()!!
                    val count = IntArray(max - min + 1)
                    for (t in types) count[t - min]++
                    var sum = 0
                    for (i in count.indices) {
                        val shift = count[i]
                        count[i] = sum
                        sum += shift
                    }
                    val sorted = arrayOfNullsSafe<T>(size)
                    for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]
                    return if (inPlace) {
                        return (this as MutableList<T>).apply {
                            for (i in indices) this[i] = sorted[i]
                        }
                    } else {
                        sorted.asList()
                    }
                }

                @Suppress("DuplicatedCode")
                inline fun IntArray.countSort(
                    inPlace: Boolean = true,
                    type: (Int) -> Int = { it -> it }
                ): IntArray {
                    if (isEmpty()) return if (inPlace) this else intArrayOf()
                    val types = IntArray(size) { type(this[it]) }
                    val min = types.minOrNull()!!
                    val max = types.maxOrNull()!!
                    val count = IntArray(max - min + 1)
                    for (t in types) count[t - min]++
                    var sum = 0
                    for (i in count.indices) {
                        val shift = count[i]
                        count[i] = sum
                        sum += shift
                    }
                    val sorted = IntArray(size)
                    for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]
                    return if (inPlace) {
                        this.also { sorted.copyInto(this) }
                    } else {
                        sorted
                    }
                }
            }
        }

        class Prints {
            companion object {
                fun println(a: IntArray) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: LongArray) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: CharArray, printSpace: Boolean = false) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            if (printSpace) print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: Array<*>) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: List<*>) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: Iterable<*>) {
                    val it = a.iterator()
                    if (it.hasNext()) {
                        print(it.next())
                        while (it.hasNext()) {
                            print(' ')
                            print(it.next())
                        }
                    }
                    println()
                }
            }
        }
    }

    class BinarySearchUtils {
        companion object {
            @Suppress("DuplicatedCode")
            inline fun binarySearch(from: Int, to: Int, f: (Int) -> Boolean): Int {
                var l = from
                var r = to + 1
                while (r - l > 1) {
                    val m = (l + r) / 2
                    if (f(m)) l = m
                    else r = m
                }
                return l
            }

            inline fun binarySearch(from: Int = 0, f: (Int) -> Boolean): Int {
                var len = 1
                while (f(from + len)) len *= 2
                return binarySearch(from + len / 2, from + len - 1, f)
            }

            @Suppress("DuplicatedCode")
            inline fun binarySearchLong(from: Long, to: Long, f: (Long) -> Boolean): Long {
                var l = from
                var r = to + 1
                while (r - l > 1) {
                    val m = (l + r) / 2
                    if (f(m)) l = m
                    else r = m
                }
                return l
            }

            inline fun binarySearchLong(from: Long = 0, f: (Long) -> Boolean): Long {
                var len = 1L
                while (f(from + len)) len *= 2
                return binarySearchLong(from + len / 2, from + len - 1, f)
            }

            @Suppress("DuplicatedCode")
            inline fun binarySearchDouble(
                from: Double,
                to: Double,
                times: Int = 200,
                f: (Double) -> Boolean
            ): Double {
                var l = from
                var r = to
                repeat(times) {
                    val m = (l + r) / 2
                    if (f(m)) l = m
                    else r = m
                }
                return l
            }

            inline fun binarySearchDouble(
                from: Double = 0.0,
                times: Int = 200,
                f: (Double) -> Boolean
            ): Double {
                var len = 1.0
                while (f(from + len)) len *= 2
                return binarySearchDouble(from, from + len, times, f)
            }
        }
    }

    class Pairs {
        companion object {
            data class ComparablePair<T1 : Comparable<T1>, T2 : Comparable<T2>>(
                val first: T1,
                val second: T2
            ) :
                Comparable<ComparablePair<T1, T2>> {
                override fun compareTo(other: ComparablePair<T1, T2>): Int {
                    var c = first.compareTo(other.first)
                    if (c == 0) c = second.compareTo(other.second)
                    return c
                }
            }

            data class IntPair(val first: Int, val second: Int) : Comparable<IntPair> {
                override fun compareTo(other: IntPair): Int {
                    var c = first.compareTo(other.first)
                    if (c == 0) c = second.compareTo(other.second)
                    return c
                }

                fun swap() = IntPair(second, first)
            }

            data class LongPair(val first: Long, val second: Long) : Comparable<LongPair> {
                override fun compareTo(other: LongPair): Int {
                    var c = first.compareTo(other.first)
                    if (c == 0) c = second.compareTo(other.second)
                    return c
                }
            }
        }
    }

    class UtilsImports {
        fun importDependencies() {
            check(gcd(4, 6) == 2)
            check(rnd.nextInt(10) in 0 until 10)
            check(mutableListOf(1, 3, 2, 2, 1).apply { makeDistinct() } == listOf(1, 2, 3))
            check((5..10).length == 6)
            check(intArrayOf(3, 4).apply { swap(0, 1) }.contentEquals(intArrayOf(4, 3)))
            check(
                intArrayOf(5, 6, 2, 1, 5).apply { shuffleSort() }
                    .contentEquals(intArrayOf(1, 2, 5, 5, 6))
            )
            check(binarySearch { it < 10 } == 9)
            check(binarySearchLong { it < 1e13.toLong() } == 1e13.toLong() - 1)
            binarySearchDouble { true }
            println(intArrayOf())
            ArrayDeque<Int>()
            abs(1)
            sin(1.0)
            cos(1.0)
            hypot(1.0, 1.0)
            catch {}
            ComparablePair(1, 2)
            IntPair(1, 2)
            arrayOfNulls<Int>(0).toNotNulls()
            arrayOfNullsSafe<Int>(0)
            5.log2()
            @Suppress("ReplaceGetOrSet")
            5.get(3)
            5.sign
            5 submaskOf 3
            5.set(3)
            5.flip(3)
            compareDoubles(0.0, 1.0)
            arrayOf(1, 2).countSort { it.countOneBits() }
            LongPair(1, 2)
        }
    }

    class FastReader(fileName: String? = null) {
        @JvmField
        val br =
            BufferedReader(if (fileName != null) FileReader(fileName) else InputStreamReader(System.`in`))

        @JvmField
        var st = StringTokenizer("")

        fun readString(): String {
            while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
            return st.nextToken()
        }

        fun readInt() = readString().toInt()
        fun readLong() = readString().toLong()
        fun readDouble() = readString().toDouble()

        fun readIntArray(n: Int) = IntArray(n) { readInt() }
        fun readLongArray(n: Int) = LongArray(n) { readLong() }
        fun readStringArray(n: Int) = Array(n) { readString() }
        fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }

        fun readInts(n: Int) = MutableList(n) { readInt() }
        fun readLongs(n: Int) = MutableList(n) { readLong() }
        fun readStrings(n: Int) = MutableList(n) { readString() }
        fun readDoubles(n: Int) = MutableList(n) { readDouble() }
    }
}


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 = 998244353
fun powMod(a: Long, n: Long, mod: Int): Long {
  if (n == 0L) return 1
  val res = powMod(a * a % mod, n / 2, mod)
  return if (n % 2 == 1L) res * a % mod else res
}

/**
 * @param mod 逆数計算するため素数でないといけない
 */
class Comb(n: Int, val mod: Int) {

  val F = LongArray(n + 1)
  val I = LongArray(n + 1)

  // n>=modでも処理できるように、*modを別扱いにする
  val cntF = IntArray(n + 1) // Fの*modの数
  val x = IntArray(n + 1) // 数値から*modを取り除いた値
  val cntX = IntArray(n + 1) // xの*modの数

  init {
    F[0] = 1
    I[0] = 1
    for (i in 1..n) {
      x[i] = i
      if(x[i] % mod == 0) {
        val j = i/mod
        cntX[i] = cntX[j] + 1
        x[i] = x[j]
      }
      F[i] = F[i - 1] * x[i] % mod
      cntF[i] += cntF[i - 1] + cntX[i]
    }

    I[n] = powMod(F[n], (mod - 2).toLong(), mod)
    for (i in n - 1 downTo 0) {
      I[i] = I[i + 1] * x[i + 1] % mod
    }
  }

  fun comb(n: Int, k: Int): Long {
    if (n < k) return 0L
    val c = cntF[n] - cntF[k] - cntF[n - k]
    return if (c > 0) 0 else F[n] * I[k] % mod * I[n - k] % mod
  }

  fun perm(n: Int, k: Int): Long {
    val c = cntF[n] - cntF[n - k]
    return if (c > 0) 0 else F[n] * I[n - k] % mod
  }

  fun inv(x: Int): Long {
    val c = cntF[x] - cntF[x - 1]
    return if (c > 0) 0 else I[x] * F[x - 1] % mod
  }

  /**
   * nのグループからk回重複ありで選ぶ組み合わせ数
   * n - 1のしきりとkの○で考える
   */
  fun H(n: Int, k: Int) = comb(n + k - 1, k)
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  private val reader = BufferedReader(InputStreamReader(stream), 32768)

  fun solve() {
    val (N, X) = na(2)
    val dp = Array(N + 1){LongArray(X + 1) } // (人数, Xmax)

    val comb = Comb(N + 10, MOD)

    val pow = Array(max(N, X) + 1){LongArray(max(N, X) + 1)}
    for (i in 0 .. max(N, X)) {
      for (j in 0 .. max(N, X)) {
        pow[i][j] = powMod(i.toLong(), j.toLong(), MOD)
      }
    }

    // 初期化。(0, 0)からの遷移
    for (i in 2 .. N) { // 残っている人数
      for (j in 1 .. min(i - 1, X)) { // 次のターンで全員死亡
        val select = comb.comb(N, i)
        val cmb = (pow[j][i] + MOD - pow[j - 1][i]) % MOD // jを含む組み合わせ
        dp[i][j] = cmb * select % MOD
      }
    }

    debug{"INIT"}
    debugDim(dp)

    for (i in 2 .. N) {
      for (j in 1 .. X) {
        for (ni in i .. N) {
          val add = ni - i
          val nj = j + (ni - 1)
          if (nj > X) continue

          val remain = N - i
          val select = comb.comb(remain, add)
          val cmb = pow[ni - 1][add]
          val c = cmb * select % MOD
          dp[ni][nj] = (dp[ni][nj] + dp[i][j] * c) % MOD
        }
      }
    }

    debug{"DP"}
    debugDim(dp)

    val ans = dp[N].sum()
    out.println(ans % MOD)
  }

  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<IntArray> {
    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<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private inline fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private inline fun debugDim(A: Array<BooleanArray>) {
    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())}

  companion object {
    // TestRunnerから呼びたいので単純なmainじゃだめ
    fun main() {
      val out = java.io.PrintWriter(System.out)
      Solver(System.`in`, out).solve()
      out.flush()
    }
  }
}

/**
 * judgeから呼ばれる
 */
fun main() = Solver.main()


@file:Suppress("EXPERIMENTAL_API_USAGE")

import Utils.ArrayUtils.Companion.arrayOfNullsSafe
import Utils.ArrayUtils.Companion.makeDistinct
import Utils.ArrayUtils.Companion.toNotNulls
import Utils.ArrayUtils.Prints.Companion.println
import Utils.ArrayUtils.Sorts.Companion.countSort
import Utils.ArrayUtils.Sorts.Companion.shuffleSort
import Utils.ArrayUtils.Swaps.Companion.swap
import Utils.BinarySearchUtils.Companion.binarySearch
import Utils.BinarySearchUtils.Companion.binarySearchDouble
import Utils.BinarySearchUtils.Companion.binarySearchLong
import Utils.BitUtils.Companion.flip
import Utils.BitUtils.Companion.get
import Utils.BitUtils.Companion.set
import Utils.BitUtils.Companion.submaskOf
import Utils.FastReader
import Utils.GeneralUtils.Companion.catch
import Utils.GeneralUtils.Companion.length
import Utils.GeneralUtils.Companion.rnd
import Utils.MathUtils.Companion.compareDoubles
import Utils.MathUtils.Companion.gcd
import Utils.MathUtils.Companion.log2
import Utils.Pairs.Companion.ComparablePair
import Utils.Pairs.Companion.IntPair
import Utils.Pairs.Companion.LongPair
import java.io.*
import java.util.*
import kotlin.collections.ArrayDeque
import kotlin.math.*
import kotlin.random.Random
import kotlin.time.ExperimentalTime

@ExperimentalStdlibApi
@ExperimentalTime
@ExperimentalUnsignedTypes
fun main() {
    Locale.setDefault(Locale.US)
    System.setOut(PrintStream(BufferedOutputStream(System.out)))
    Task(FastReader()).solve()
    System.out.flush()
}

const val eps = 1e-8

const val mod = 998244353

inline class MInt(val x: Int) {
    operator fun plus(m: MInt) = MInt((x + m.x) % mod)
    operator fun minus(m: MInt) = MInt((x - m.x + mod) % mod)
    operator fun times(m: MInt) = MInt((x.toLong() * m.x % mod).toInt())
    operator fun div(m: MInt) = this * m.inv()

    fun inv() = inv(x)
    fun pow(p: Int): MInt {
        if (p == 0) return MInt(1)
        var r = pow(p / 2)
        r *= r
        if (p % 2 == 1) r *= this
        return r
    }

    override fun toString() = x.toString()

    companion object {
        private val facts = mutableListOf(MInt(1))
        private val invs = mutableListOf(MInt(0))
        private val invFacts = mutableListOf(MInt(1))
        fun Int.mod() = MInt(this)

        fun factorial(x: Int): MInt {
            while (x !in facts.indices) facts += facts.last() * facts.size.mod()
            return facts[x]
        }

        fun inv(x: Int): MInt {
            while (x !in invs.indices) invs += MInt((mod - mod / x) % mod) * inv(mod % x)
            return x.mod().pow(mod - 2)
        }

        fun invFact(x: Int): MInt {
            while (x !in invFacts.indices) invFacts += invFacts.last() * inv(invFacts.size)
            return invFacts[x]
        }
    }
}

fun c(n: Int, k: Int) = if (k in 0..n) MInt.factorial(n) * MInt.invFact(k) * MInt.invFact(n - k) else MInt(0)

@ExperimentalTime
@ExperimentalStdlibApi
class Task(private val fin: FastReader = FastReader()) {
    fun solve() {
        val n = fin.readInt()
        val maxHealth = fin.readInt()

        val powers = Array(maxHealth + 1) { x ->
            Array(n + 1) { null as MInt? }.apply {
                this[0] = MInt(1)
                for (p in 1 until size) this[p] = this[p - 1]!! * MInt(x)
            } as Array<MInt>
        }

        val cache = Array(n + 1) { IntArray(maxHealth + 1) { -1 } }
        fun go(alive: Int, damageGot: Int): MInt {
            if (alive == 0) return MInt(1)
            if (damageGot > maxHealth) return MInt(0)
            if (alive == 1) return MInt(0)
            cache[alive][damageGot].let { if (it != -1) return MInt(it) }
            var res = go(alive, damageGot + alive - 1)
            for (died in 1..alive) {
                val survived = alive - died
                val minWas = 1 + damageGot
                val maxWas = minOf(alive - 1 + damageGot, maxHealth)
                val numberOfWaysDied = c(alive, died)
                val healthForDied = powers[maxWas - minWas + 1][died]
                res += go(survived, damageGot + alive - 1) * numberOfWaysDied * healthForDied
            }
            cache[alive][damageGot] = res.x
            return res
        }

        val ans = go(n, 0)
        println(ans)
    }
}

@Suppress("MemberVisibilityCanBePrivate", "unused")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
class Utils {
    class GeneralUtils {
        companion object {
            val rnd = Random(239)
            val IntRange.length get() = maxOf(last - first + 1, 0)

            @Suppress("UNREACHABLE_CODE", "ControlFlowWithEmptyBody")
            fun <R> catch(throwMLE: Boolean = false, f: () -> R): R {
                try {
                    return f()
                } catch (e: Exception) {
                    if (throwMLE) throw OutOfMemoryError()
                    while (true) {
                    }
                }
            }
        }
    }

    class MathUtils {
        companion object {
            tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
            tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
            fun lcm(a: Long, b: Long) = a / gcd(a, b) * b

            fun Int.log2(): Int {
                var log = 0
                while (1 shl log < this) log++
                return log
            }

            fun Long.log2(): Int {
                var log = 0
                while (1L shl log < this) log++
                return log
            }

            fun compareDoubles(x: Double, y: Double) =
                if (abs(x - y) < eps) 0 else if (x < y) -1 else +1

            fun isZero(x: Double) = abs(x) < eps
        }
    }

    class BitUtils {
        companion object {
            operator fun Int.get(bit: Int) = (this shr bit) and 1
            operator fun Long.get(bit: Int) = ((this shr bit) and 1).toInt()
            fun Int.set(bit: Int) = this or (1 shl bit)
            fun Long.set(bit: Int) = this or (1L shl bit)
            fun Int.flip(bit: Int) = this xor (1 shl bit)
            fun Long.flip(bit: Int) = this xor (1L shl bit)
            infix fun Int.submaskOf(x: Int) = (this and x) == this
            infix fun Long.submaskOf(x: Long) = (this and x) == this
        }
    }

    class ArrayUtils {
        companion object {
            fun <T : Comparable<T>> MutableList<T>.makeDistinct() {
                if (size <= 1) return
                sort()
                var sz = 1
                for (i in 1 until size) {
                    if (this[i] != this[i - 1]) {
                        this[sz++] = this[i]
                    }
                }
                while (size > sz) removeAt(lastIndex)
            }

            @Suppress("UNCHECKED_CAST")
            fun <T> Array<T?>.toNotNulls() = this as Array<T>

            @Suppress("UNCHECKED_CAST")
            inline fun <reified T> arrayOfNullsSafe(size: Int): Array<T> =
                arrayOfNulls<T>(size).toNotNulls()
        }

        class Swaps {
            companion object {
                fun <T> Array<T>.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                }

                fun <T> MutableList<T>.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                }

                fun IntArray.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                }

                fun LongArray.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                }

                fun DoubleArray.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                    sort()
                }

                fun CharArray.swap(i: Int, j: Int) {
                    val x = this[i]
                    this[i] = this[j]
                    this[j] = x
                    sort()
                }
            }
        }

        class Sorts {
            companion object {
                fun IntArray.shuffleSort() {
                    for (i in 1 until size) swap(i, rnd.nextInt(i + 1))
                    sort()
                }

                fun LongArray.shuffleSort() {
                    for (i in 1 until size) swap(i, rnd.nextInt(i + 1))
                    sort()
                }

                fun DoubleArray.shuffleSort() {
                    for (i in 1 until size) swap(i, rnd.nextInt(i + 1))
                    sort()
                }

                fun CharArray.shuffleSort() {
                    for (i in 1 until size) swap(i, rnd.nextInt(i + 1))
                    sort()
                }

                @Suppress("DuplicatedCode")
                inline fun <reified T> Array<T>.countSort(
                    inPlace: Boolean = true,
                    type: (T) -> Int = { (it as Number).toInt() }
                ): Array<T> {
                    if (isEmpty()) return if (inPlace) this else emptyArray()
                    val types = IntArray(size) { type(this[it]) }
                    val min = types.minOrNull()!!
                    val max = types.maxOrNull()!!
                    val count = IntArray(max - min + 1)
                    for (t in types) count[t - min]++
                    var sum = 0
                    for (i in count.indices) {
                        val shift = count[i]
                        count[i] = sum
                        sum += shift
                    }
                    val sorted = arrayOfNullsSafe<T>(size)
                    for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]
                    return if (inPlace) {
                        this.also { sorted.copyInto(this) }
                    } else {
                        sorted
                    }
                }

                @Suppress("DuplicatedCode")
                inline fun <reified T> List<T>.countSort(
                    inPlace: Boolean = true,
                    type: (T) -> Int = { (it as Number).toInt() }
                ): List<T> {
                    if (isEmpty()) return if (inPlace) this else emptyList()
                    val types = IntArray(size) { type(this[it]) }
                    val min = types.minOrNull()!!
                    val max = types.maxOrNull()!!
                    val count = IntArray(max - min + 1)
                    for (t in types) count[t - min]++
                    var sum = 0
                    for (i in count.indices) {
                        val shift = count[i]
                        count[i] = sum
                        sum += shift
                    }
                    val sorted = arrayOfNullsSafe<T>(size)
                    for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]
                    return if (inPlace) {
                        return (this as MutableList<T>).apply {
                            for (i in indices) this[i] = sorted[i]
                        }
                    } else {
                        sorted.asList()
                    }
                }

                @Suppress("DuplicatedCode")
                inline fun IntArray.countSort(
                    inPlace: Boolean = true,
                    type: (Int) -> Int = { it -> it }
                ): IntArray {
                    if (isEmpty()) return if (inPlace) this else intArrayOf()
                    val types = IntArray(size) { type(this[it]) }
                    val min = types.minOrNull()!!
                    val max = types.maxOrNull()!!
                    val count = IntArray(max - min + 1)
                    for (t in types) count[t - min]++
                    var sum = 0
                    for (i in count.indices) {
                        val shift = count[i]
                        count[i] = sum
                        sum += shift
                    }
                    val sorted = IntArray(size)
                    for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]
                    return if (inPlace) {
                        this.also { sorted.copyInto(this) }
                    } else {
                        sorted
                    }
                }
            }
        }

        class Prints {
            companion object {
                fun println(a: IntArray) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: LongArray) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: CharArray, printSpace: Boolean = false) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            if (printSpace) print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: Array<*>) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: List<*>) {
                    if (a.isNotEmpty()) {
                        print(a[0])
                        for (i in 1 until a.size) {
                            print(' ')
                            print(a[i])
                        }
                    }
                    println()
                }

                fun println(a: Iterable<*>) {
                    val it = a.iterator()
                    if (it.hasNext()) {
                        print(it.next())
                        while (it.hasNext()) {
                            print(' ')
                            print(it.next())
                        }
                    }
                    println()
                }
            }
        }
    }

    class BinarySearchUtils {
        companion object {
            @Suppress("DuplicatedCode")
            inline fun binarySearch(from: Int, to: Int, f: (Int) -> Boolean): Int {
                var l = from
                var r = to + 1
                while (r - l > 1) {
                    val m = (l + r) / 2
                    if (f(m)) l = m
                    else r = m
                }
                return l
            }

            inline fun binarySearch(from: Int = 0, f: (Int) -> Boolean): Int {
                var len = 1
                while (f(from + len)) len *= 2
                return binarySearch(from + len / 2, from + len - 1, f)
            }

            @Suppress("DuplicatedCode")
            inline fun binarySearchLong(from: Long, to: Long, f: (Long) -> Boolean): Long {
                var l = from
                var r = to + 1
                while (r - l > 1) {
                    val m = (l + r) / 2
                    if (f(m)) l = m
                    else r = m
                }
                return l
            }

            inline fun binarySearchLong(from: Long = 0, f: (Long) -> Boolean): Long {
                var len = 1L
                while (f(from + len)) len *= 2
                return binarySearchLong(from + len / 2, from + len - 1, f)
            }

            @Suppress("DuplicatedCode")
            inline fun binarySearchDouble(
                from: Double,
                to: Double,
                times: Int = 200,
                f: (Double) -> Boolean
            ): Double {
                var l = from
                var r = to
                repeat(times) {
                    val m = (l + r) / 2
                    if (f(m)) l = m
                    else r = m
                }
                return l
            }

            inline fun binarySearchDouble(
                from: Double = 0.0,
                times: Int = 200,
                f: (Double) -> Boolean
            ): Double {
                var len = 1.0
                while (f(from + len)) len *= 2
                return binarySearchDouble(from, from + len, times, f)
            }
        }
    }

    class Pairs {
        companion object {
            data class ComparablePair<T1 : Comparable<T1>, T2 : Comparable<T2>>(
                val first: T1,
                val second: T2
            ) :
                Comparable<ComparablePair<T1, T2>> {
                override fun compareTo(other: ComparablePair<T1, T2>): Int {
                    var c = first.compareTo(other.first)
                    if (c == 0) c = second.compareTo(other.second)
                    return c
                }
            }

            data class IntPair(val first: Int, val second: Int) : Comparable<IntPair> {
                override fun compareTo(other: IntPair): Int {
                    var c = first.compareTo(other.first)
                    if (c == 0) c = second.compareTo(other.second)
                    return c
                }

                fun swap() = IntPair(second, first)
            }

            data class LongPair(val first: Long, val second: Long) : Comparable<LongPair> {
                override fun compareTo(other: LongPair): Int {
                    var c = first.compareTo(other.first)
                    if (c == 0) c = second.compareTo(other.second)
                    return c
                }
            }
        }
    }

    class UtilsImports {
        fun importDependencies() {
            check(gcd(4, 6) == 2)
            check(rnd.nextInt(10) in 0 until 10)
            check(mutableListOf(1, 3, 2, 2, 1).apply { makeDistinct() } == listOf(1, 2, 3))
            check((5..10).length == 6)
            check(intArrayOf(3, 4).apply { swap(0, 1) }.contentEquals(intArrayOf(4, 3)))
            check(
                intArrayOf(5, 6, 2, 1, 5).apply { shuffleSort() }
                    .contentEquals(intArrayOf(1, 2, 5, 5, 6))
            )
            check(binarySearch { it < 10 } == 9)
            check(binarySearchLong { it < 1e13.toLong() } == 1e13.toLong() - 1)
            binarySearchDouble { true }
            println(intArrayOf())
            ArrayDeque<Int>()
            abs(1)
            sin(1.0)
            cos(1.0)
            hypot(1.0, 1.0)
            catch {}
            ComparablePair(1, 2)
            IntPair(1, 2)
            arrayOfNulls<Int>(0).toNotNulls()
            arrayOfNullsSafe<Int>(0)
            5.log2()
            @Suppress("ReplaceGetOrSet")
            5.get(3)
            5.sign
            5 submaskOf 3
            5.set(3)
            5.flip(3)
            compareDoubles(0.0, 1.0)
            arrayOf(1, 2).countSort { it.countOneBits() }
            LongPair(1, 2)
        }
    }

    class FastReader(fileName: String? = null) {
        @JvmField
        val br =
            BufferedReader(if (fileName != null) FileReader(fileName) else InputStreamReader(System.`in`))

        @JvmField
        var st = StringTokenizer("")

        fun readString(): String {
            while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
            return st.nextToken()
        }

        fun readInt() = readString().toInt()
        fun readLong() = readString().toLong()
        fun readDouble() = readString().toDouble()

        fun readIntArray(n: Int) = IntArray(n) { readInt() }
        fun readLongArray(n: Int) = LongArray(n) { readLong() }
        fun readStringArray(n: Int) = Array(n) { readString() }
        fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }

        fun readInts(n: Int) = MutableList(n) { readInt() }
        fun readLongs(n: Int) = MutableList(n) { readLong() }
        fun readStrings(n: Int) = MutableList(n) { readString() }
        fun readDoubles(n: Int) = MutableList(n) { readDouble() }
    }
}


fun main(args: Array<String>) {
    println(4 - readLine()!!.split(' ').map { it.toInt() }.toSet().size)
}


fun main() = (4 - hashSetOf<String>().apply { addAll(readLine()!!.split(" ")) }.size).run(::println)


import java.util.*

fun main() {
    val reader = Scanner(System.`in`)
    val t = reader.nextLine().split(" ").toSet()
    println(4-t.size)
}


import java.util.*

fun main(args: Array<String>) {
    val shoes = Scanner(System.`in`).nextLine().split(" ").map{it.toInt()}
    val distinct = HashSet<Int>()
    var ans = 0

    for(i in shoes.indices) {
        if(distinct.contains(shoes[i])) {
            ans++
        }
        else {
            distinct.add(shoes[i])
        }
    }

    println(ans)
}


// solved easily, but the tutorial is worth reading:
//This task is about pure implementation. Maintain the number of current spectator and check if he doesn't win.
// With knowledge of current winner w and current spectator s you can easily get the third player by formula
// 6 - w - s (just the sum of all numbers without the known ones).

// My solution
//fun main() {
//    fun readInt() = readLine()!!.toInt()
//
//    val numGames = readInt()
//    val playing = booleanArrayOf(true, true, false)
//    repeat(numGames) {
//        val winner = readInt() - 1
//        if (!playing[winner]) return print("NO")
//        for (player in 0..2)
//            if (player != winner)
//                playing[player] = !playing[player]
//    }
//    print("YES")
//}

// Tutorial solution
fun main() {
    fun readInt() = readLine()!!.toInt()

    val numGames = readInt()
    var out = 3
    repeat(numGames) {
        val winner = readInt()
        if (winner == out) return print("NO")
        out = 6 - winner - out
    }
    print("YES")
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val n = sc.nextInt()

    val pl = arrayOf(true, true, false)

    repeat(n) {
        val win = sc.nextInt()

        if (!pl[win - 1]) {
            println("NO")
            return
        }

        var lost = 0
        for (i in 1..3) {
            if (pl[i - 1] && i != win) lost = i
        }

        for (i in 1..3) {
            pl[i - 1] = true
            if( i == lost) pl[i - 1] = false
        }
    }

    println("YES")

}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


import java.io.*
import java.util.*

class Main internal constructor(inputStream: InputStream, val out: PrintWriter) {
    companion object {
        val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null
    }

    private val br = BufferedReader(InputStreamReader(inputStream))
    private var st = StringTokenizer("")

    internal fun hasNext(): Boolean {
        while (!st.hasMoreTokens()) {
            val readLine = br.readLine() ?: return false
            st = StringTokenizer(readLine)
        }
        return true
    }

    private operator fun next() =
            if (hasNext()) st.nextToken()!!
            else throw RuntimeException("No tokens")

    internal fun nline() =
            if (hasNext()) st.nextToken("\n")
            else throw RuntimeException("No tokens")

    private fun ni() = next().toInt()
    private fun nii() = Pair(ni(), ni())
    private fun niii() = Triple(ni(), ni(), ni())
    private fun nia(n: Int) = IntArray(n) { ni() }
    private fun nia(m: Int, n: Int) = Array(m) { nia(n) }

    private fun nl() = next().toLong()
    private fun nll() = Pair(nl(), nl())
    private fun nlll() = Triple(nl(), nl(), nl())
    private fun nla(n: Int) = LongArray(n, { nl() })
    private fun nla(m: Int, n: Int) = Array(m) { nla(n) }

    private fun nd() = next().toDouble()
    private fun ndd() = Pair(nd(), nd())
    private fun nddd() = Triple(nd(), nd(), nd())
    private fun nda(n: Int) = DoubleArray(n) { nd() }
    private fun nda(m: Int, n: Int) = Array(m) { nda(n) }

    inline fun log(name: String, block: () -> Unit) {
        if (!ONLINE_JUDGE) {
            p("#$name: ")
            block()
            flush()
        }
    }

    inline fun log() = log("") { pln() }
    inline fun log(message: Any?, name: String = "") = log(name) { pln(message) }
    inline fun log(arr: IntArray?, name: String = "") = log(name) { pln(arr) }
    inline fun log(arr: LongArray?, name: String = "") = log(name) { pln(arr) }
    inline fun log(arr: DoubleArray?, name: String = "") = log(name) { pln(arr) }
    inline fun <T> log(arr: Array<T>?, name: String = "") = log(name) { pln(arr) }
    inline fun <T> log(stack: Stack<T>?, name: String = "") = log(name) { pln(stack) }
    inline fun <T> log(list: List<T>?, name: String = "") = log(name) { pln(list) }

    //prefix print
    inline fun prep(prefix: Boolean, separator: String, message: Any?) {
        if (prefix) {
            p(separator)
        }
        p(message)
    }

    inline fun p(message: Any?) = this.also { out.print(message) }

    inline fun p(arr: IntArray?, separator: String = " ") = this.also {
        arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })
    }

    inline fun p(arr: LongArray?, separator: String = " ") = this.also {
        arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })
    }

    inline fun p(arr: DoubleArray?, separator: String = " ") = this.also {
        arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })
    }

    inline fun <T> p(arr: Array<T>?, separator: String = " ") = this.also {
        arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })
    }

    inline fun <T> p(list: List<T>?, separator: String = " ") = this.also {
        list?.fold(false, { prefix, t -> prep(prefix, separator, t); true })
    }

    inline fun <T> p(stack: Stack<T>?, separator: String = " ") = this.also {
        stack?.fold(false, { prefix, t -> prep(prefix, separator, t); true })
    }

    inline fun pln() = this.also { out.println() }
    inline fun pln(message: Any?) = p(message).pln()
    inline fun pln(arr: IntArray?, separator: String = " ") = p(arr, separator).pln()
    inline fun pln(arr: LongArray?, separator: String = " ") = p(arr, separator).pln()
    inline fun pln(arr: DoubleArray?, separator: String = " ") = p(arr, separator).pln()
    inline fun <T> pln(list: List<T>?, separator: String = " ") = p(list, separator).pln()
    inline fun <T> pln(arr: Array<T>?, separator: String = " ") = p(arr, separator).pln()
    inline fun <T> pln(stack: Stack<T>?, separator: String = " ") = p(stack, separator).pln()

    inline fun flush() = out.flush()

    //////////////////////////////////////

    fun run() {
        val n = ni()
        var next = 0
        var playing1 = 1
        var playing2 = 2
        val check = HashSet<Int>()
        var winner = 0;
        for (i in 0..n - 1) {
            next = ni();
            if(next!=playing1&&next!=playing2){
                pln("NO")
                return
            }
            winner = next;
            for (i in 1..3) check.add(i)
            check.remove(playing1)
            check.remove(playing2)
            playing1=check.first();
            playing2=winner;
        }
        pln("YES")
    }

}

//////////////////////////////////////
fun main(args: Array<String>) {
    val inp = File("input.txt")
    if (Main.ONLINE_JUDGE || !inp.isFile) {
        val a = Main(System.`in`, PrintWriter(BufferedOutputStream(System.out)))
        a.run()
        a.flush()
        a.out.close()
    } else {
        val t = Main(FileInputStream("input.txt"), PrintWriter(BufferedOutputStream(System.out)))
        while (t.hasNext()) {
            val name = t.nline()
            t.log("##### Test $name #####")
            val startTime = System.currentTimeMillis()
            t.run()
            val endTime = System.currentTimeMillis()
            t.log(endTime - startTime, "Total Time")
            t.log()
            t.flush()
        }
    }
}


import java.io.*
import java.util.*

fun main(args: Array<String>) {
    solve(System.`in`, System.out)
}

val MAX_N = (1e6 + 10).toInt()
val INF = (1e9 + 7).toInt()
val MOD = (1e9 + 7).toInt()
val INF_F = 1e-6

fun solve(input: InputStream, output: OutputStream) {
    val reader = InputReader(BufferedInputStream(input))
    val writer = PrintWriter(BufferedOutputStream(output))

    solve(reader, writer)
    writer.close()
}

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextInt()
    val player = BooleanArray(3) { it < 2 }
    for (i in 0 until n) {
        val x = reader.nextInt() - 1
        if (!player[x]) {
            writer.println("NO")
            return
        }

        val visor = player.indexOf(false)
        for (j in player.indices) {
            if (player[j] && j != x) {
                player[j] = false
                break
            }
        }
        player[visor] = true
    }
    writer.println("YES")
}

fun gcd(a: Int, b: Int): Int {
    return if (b == 0) a else gcd(b, a % b)
}

class InputReader(stream: InputStream) {
    private val reader = BufferedReader(InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer? = null

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }

    fun nextArrayInt(count: Int): IntArray {
        return nextArrayInt(0, count)
    }

    fun nextArrayInt(start: Int, count: Int): IntArray {
        val a = IntArray(start + count)
        for (i in start until start + count) {
            a[i] = nextInt()
        }
        return a
    }

    fun nextArrayLong(count: Int): LongArray {
        val a = LongArray(count)
        for (i in 0 until count) {
            a[i] = nextLong()
        }
        return a
    }
}


import java.io.PrintWriter
import kotlin.math.min

fun main() {
    io.apply {

        val (m, s) = int to int

        if (s == 0 && m == 1) {
            cout .. 0 .. 0 .. nl
        } else if (s <= 0 || s > m * 9)
            cout .. -1 .. -1 .. nl
        else {
            val str = CharArray(m) { '0' }
            str[0] = '1'
            var q = s - 1
            for (i in m - 1 downTo 0) {
                var d = min(9, q)
                str[i] = (str[i] + d)
                q -= d
            }
            cout .. String(str) .. " "
            str.fill('0')
            q = s
            for (i in 0 until m) {
                var d = min(9, q)
                str[i] = (str[i] + d)
                q -= d
            }
            cout .. String(str) .. nl
        }

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */


import java.io.BufferedReader
import java.io.InputStreamReader

fun main() {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val (m, s) = reader.readLine().split(' ').map { it.toInt() }

    if (s == 0) {
        val answer = if (m == 1) 0 else -1
        println("$answer $answer")
        return
    }

    val maxN = Array<Int>(m) { if (it == 0) 1 else 0 }
    val minN = Array<Int>(m) { if (it == 0) 1 else 0 }

    var maxNPtr = 0
    var minNPtr = minN.lastIndex

    try {
        repeat(s-1) {
            if (maxN[maxNPtr] == 9) { maxNPtr++ }
            if (minN[minNPtr] == 9) { minNPtr-- }

            maxN[maxNPtr]++
            minN[minNPtr]++
        }
    } catch (e: IndexOutOfBoundsException) {
        println("-1 -1")
        return
    }

    println("${minN.joinToString("")} ${maxN.joinToString("")}")
}


import kotlin.math.max

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }
fun findMin(m: Int, s: Int): String{
    val digits = (m-2 downTo 0).toMutableList()
    if (s > m * 9) return "-1"
    if(digits.size == 0) return "$s"
    val result = mutableListOf(max(1, s - 9*(m-1)))
    var auxS = s - result[0]
    var auxM = m - 1
    var index = 0
    while(auxM != 0 || auxS != 0){
        val value = max(0, auxS - 9 * digits[index])
        result.add(value)
        index ++
        auxS -= value
        auxM --
        if(auxM == 0) break
    }
    if(result.isEmpty() || auxM + auxS != 0){
        return "-1"
    }
    return result.joinToString(separator = "")
}
fun findMax(m: Int, s: Int): String{
    val digits = (9 downTo 0).toMutableList()
    var auxS = s
    var auxM = m
    val result = mutableListOf<Int>()
    var index = 0
    if( m == 1 && s <= 9)
    {
        return "$s"
    }
    while(auxM != 0 || auxS != 0){
        if(auxS - digits[index] >= 0){
            result.add(digits[index])
            auxS -= digits[index]
            auxM --
        }
        if(auxS < digits[index]){
            index ++
        }
        if(auxM == 0) break
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || auxM + auxS != 0){
        return "-1"
    }
    return result.joinToString(separator = "")
}

fun main(){
    val (m, s) = readInts()

    println("${findMin(m, s)} ${findMax(m,s)}")
}


import kotlin.math.min

/* template start */
// input
private fun readString() = readLine()!!
private fun readStrings() = readString().split(" ")
private fun readInt() = readString().toInt()
private fun readDigits() = readString().map { it - '0' }
private fun readInts() = readStrings().map { it.toInt() }
private fun readLongs() = readStrings().map { it.toLong() }

// output
private fun <T> T.print(map: (T) -> String = { it.toString() }) = println(map(this))
private fun <T> Iterable<T>.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)
private fun <T> Array<T>.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)
private fun IntArray.print(sep: String? = null, map: ((Int) -> String)? = null) = asSequence().print(sep, map)
private fun <T> Sequence<T>.print(sep: String? = null, map: ((T) -> String)? = null) =
    println(joinToString(sep ?: "", transform = map ?: { it.toString() }))

// others
private val Int.isEven: Boolean get() = this % 2 == 0
private val Int.isOdd: Boolean get() = !this.isEven
private fun queries(block: (Int) -> Unit) = repeat(readInt(), block)

/* template end */

fun main() {
    val (len, sum) = readInts()
    if (sum == 0) {
        if (len != 1) println("-1 -1")
        else println("0 0")
    } else if (len * 9 < sum) {
        println("-1 -1")
    } else {
        val maxNum = buildString {
            var rem = sum
            repeat(len) {
                val next = min(rem, 9)
                append(next)
                rem -= next
            }
        }
        val minNum = mutableListOf<Int>()
        var rem = sum
        for (i in 0 until len) {
            if (rem > 1) {
                var next = min(rem - 1, 9)
                if (i == len - 1) {
                    next++
                }
                minNum.add(0, next)
                rem -= next
            } else {
                if (i != len - 1)
                    minNum.add(0, 0)
                else minNum.add(0, 1)
            }
        }

        println("${minNum.joinToString("")} $maxNum")
    }

}


//package com.happypeople.codeforces.c1131

import java.io.ByteArrayInputStream
import java.io.InputStream
import java.util.*

fun main(args: Array<String>) {
    try {
        A1131().run()
    } catch (e: Throwable) {
        println("")
        e.printStackTrace()
    }
}

class A1131 {
    fun run() {
        val sc = Scanner(systemIn())
        val w1=sc.nextInt()
        val h1=sc.nextInt()
        val w2=sc.nextInt()
        val h2=sc.nextInt()

        val lb1=Pair(1, 1)
        val rt1=Pair(w1, h1)
        val lb2=Pair(1, h1+1)
        val rt2=Pair(w2, h1+h2)

        var ans=(w1+2)+(h1*2) + (h2*2) + 2 + w2 + (w1-w2)
        println("$ans")
    }

    companion object {
        var inputStr: String? = null

        fun systemIn(): InputStream {
            if (inputStr != null)
                return ByteArrayInputStream(inputStr!!.toByteArray())
            else
                return System.`in`
        }

        var printLog = false
        fun log(str: String) {
            if (printLog)
                println(str)
        }
    }
}


import kotlin.math.max

fun main(args: Array<String>) {
    val (w1, h1, w2, h2) = readLine()!!.split(" ").map(String::toInt)
    val answer = 2 * (h1 + h2) + 2 * max(w1, w2) + 4
    println(answer)
}


import java.lang.Math.abs

fun main() {
    val (w1, h1, w2, h2) = readLine()!!.split(' ').map(String::toInt)
    print(w1 + w2 + 4 + 2 * (h1 + h2) + abs(w1 - w2))
}


import java.io.*
import java.util.*

fun main(args: Array<String>) {
    solve(System.`in`, System.out)
}

val MAX_N = (1e6 + 10).toInt()
val INF = (1e9 + 7).toInt()
val MOD = (1e9 + 7).toInt()
val INF_F = 1e-6

fun solve(input: InputStream, output: OutputStream) {
    val reader = InputReader(BufferedInputStream(input))
    val writer = PrintWriter(BufferedOutputStream(output))

    solve(reader, writer)
    writer.close()
}

fun solve(reader: InputReader, writer: PrintWriter) {
    val w1 = reader.nextInt()
    val h1 = reader.nextInt()
    val w2 = reader.nextInt()
    val h2 = reader.nextInt()

    val ans = (w1 + 2 * h1 + 2) + (w2 + 2 * h2 + 2) + (w1 - w2)
    writer.println(ans)
}

fun gcd(a: Int, b: Int): Int {
    return if (b == 0) a else gcd(b, a % b)
}

class InputReader(stream: InputStream) {
    private val reader = BufferedReader(InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer? = null

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }

    fun nextArrayInt(count: Int): IntArray {
        return nextArrayInt(0, count)
    }

    fun nextArrayInt(start: Int, count: Int): IntArray {
        val a = IntArray(start + count)
        for (i in start until start + count) {
            a[i] = nextInt()
        }
        return a
    }

    fun nextArrayLong(count: Int): LongArray {
        val a = LongArray(count)
        for (i in 0 until count) {
            a[i] = nextLong()
        }
        return a
    }
}


fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    infix fun Long.maxMin(b: Long): Pair<Long, Long> {
        return if (this >= b) this to b else b to this
    }

    fun gcd(a: Long, b: Long): Long {
        var (max, min) = a maxMin b
        while (min != 0L) {
            val newMin = max % min
            max = min
            min = newMin
        }
        return max
    }

    var (a, b, n) = readLongs()

    while (true) {
        n -= gcd(a, n)
        if (n < 0) {
            print(1)
            return
        }
        n -= gcd(b, n)
        if (n < 0) {
            print(0)
            return
        }
    }
}


import kotlin.math.max
import kotlin.math.min

fun main() {
    val input = readLine()!!.split(" ").map(String::toInt)
    val a = input[0]
    val b = input[1]
    var n = input[2]

    var isA = true
    while (n > 0) {
        val player = if (isA) "a" else "b"
//        println("$player's Turn")

        val value = if (isA) a else b
        val removed = gcd(n, value)
//        println("Removed: $removed")

        n -= removed
//        println("$n left")

        isA = !isA
//        println()
    }

    if (isA) {
        println(1)
    } else {
        println(0)
    }

}

fun gcd(a: Int, b: Int): Int {
    if (a == 0) {
        return b
    }
    if (b == 0) {
        return a
    }

    val min = min(a, b)
    val max = max(a, b)

    return gcd(min, max % min)
}


import java.math.BigInteger

fun main() {
    var (a, b, n) = readLine()!!.split(' ').map { it.toInt() }
    var flag = false
    while (n>0){
        if (!flag){
            if (n-gcd(a,n)>=0){
                n-=gcd(a,n)
                flag = true
            }
        }else{
            if (n-gcd(b,n)>=0){
                n-=gcd(b,n)
                flag = false
            }
        }
    }
    if (!flag){
        println(1)
    }else{
        println(0)
    }

}

fun gcd(a: Int, b: Int): Int {
    var i = 1
    var gcd = 1
    while (i <= a && i <= b) {
        if (a % i == 0 && b % i == 0) {
            gcd = i
        }
        i++
    }
    return gcd
}


import java.io.*
import java.util.*

class ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {
    var tok = StringTokenizer("")

    companion object {
        fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))
        fun files(inputFilename: String, outputFilename: String) = ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))
    }

    fun readToken(): String {
        while (!tok.hasMoreTokens()) {
            tok = StringTokenizer(rd.readLine())
        }
        return tok.nextToken()
    }

    fun readInt(): Int = readToken().toInt()
    fun <T> print(v: T) = wr.print(v)
    fun <T> println(v: T) = wr.println(v)
    fun close() {
        rd.close()
        wr.close()
    }
}

fun solve() {
    fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)

    val io = ProblemIO.console()
    val v = IntArray(2)
    v[0] = io.readInt()
    v[1] = io.readInt()
    val n = io.readInt()
    var cur = 0
    var r = n
    while (true) {
        val g = gcd(r, v[cur])
        cur = 1 - cur
        if (g > r) break
        r -= g
    }
    io.println(cur)
    io.close()
}

fun main(args: Array<String>) {
    Thread({ solve() }).start()
}


import kotlin.math.min

fun main() {
    val board = Array(8) { CharArray(8) }
    for (numRow in 0 until 8)
        board[numRow] = readLine()!!.toCharArray()
    var bestB = Int.MAX_VALUE
    var bestW = Int.MAX_VALUE
    for (row in 0 until 8)
        loop@ for (column in 0 until 8) {
            when (board[row][column]) {
                'B' -> {
                    for (rowCheck in row + 1 until 8)
                        if (board[rowCheck][column] == 'W') continue@loop
                    bestB = min(bestB, 7 - row)
                }
                'W' -> {
                    for (rowCheck in row - 1 downTo 0)
                        if (board[rowCheck][column] == 'B') continue@loop
                    bestW = min(bestW, row)
                }
            }
        }
    print(if (bestB < bestW) 'B' else 'A')
}


import java.lang.Integer.min

fun main(args: Array<String>) {
    var t = arrayListOf<String>()
    repeat(8) { t.add(readLine()!!) }
    var (a, b) = 8 to 8
    for (i in 0..7) {
        t.map { it[i] }.foldIndexed(false to 8) { i, acc, c ->
            var (metB, bestB) = acc
            if (c == 'W') bestB = 8
            if (c == 'W' && !metB) a = min(a, i)
            if (c == 'B') {
                metB = true
                bestB = 7 - i
            }

            metB to bestB
        }.let { b = min(b, it.second) }
    }
    print(if (b < a) "B" else "A")
}


import java.lang.Integer.min

fun main(args: Array<String>) {
    var t = arrayListOf<String>()
    repeat(8) { t.add(readLine()!!) }
    var (a, b) = 8 to 8
    for (i in 0..7) {
        t.map { it[i] }.foldIndexed(false to 8) { i, acc, c ->
            val (metB, _) = acc
            when {
                c == 'W' && !metB -> {
                    a = min(a, i)
                    acc
                }
                c == 'W' -> metB to 8
                c == 'B' -> true to 7 - i
                else -> acc
            }
        }.let { b = min(b, it.second) }
    }
    print(if (b < a) "B" else "A")
}


import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs

fun main(args: Array<String>) {
    b()
}

fun divisor(n: Int): Int {
    var i = 2
    while (i * i <= n) {
        if (n % i == 0) return i
        i++
    }
    return n
}

fun a() {
    repeat(readInt()) {
        val n = readInt()
        val a = List<Int>(n) { 1 }
        println(a.joinToString(separator = " "))
    }
}

fun pow(a: Int, b: Int): Long {
    var res = 1L
    repeat(b) { res *= a }
    return res
}

fun adj(i: Int, j: Int, n: Int, m: Int): Int {
    var adj = 4
    if (i == 0) adj--
    if (j == 0) adj--
    if (i == n - 1) adj--
    if (j == m - 1) adj--
    return adj
}

fun activeAdj(i: Int, j: Int, n: Int, m: Int, a: Array<IntArray>): Int {
    var activeAdj = 0
    if (i - 1 >= 0 && a[i - 1][j] > 0) activeAdj++
    if (j - 1 >= 0 && a[i][j - 1] > 0) activeAdj++
    if (i + 1 < n && a[i + 1][j] > 0) activeAdj++
    if (j + 1 < m && a[i][j + 1] > 0) activeAdj++
    return activeAdj
}

fun b() {
    repeat(readInt()) {
        val n = readInt()
        val divisor = leastDivisor(n)

        if (divisor == 1) {
            println("1 ${n - 1}")
        } else {
            println("${n / divisor} ${n - n / divisor}")
        }
    }
}

fun c() {
    repeat(readInt()) {
        val n = readInt()
        val a = readInts()

        val right = mutableListOf<Int>()
        val notRight = mutableListOf<Int>()

        for (i in 0 until n) {
            if (a[i] == i + 1) {
                right.add(i)
            } else {
                notRight.add(i)
            }
        }

        if (notRight.isEmpty()) {
            println(0)
            return@repeat
        }

        var isSubsequent = true
        for (i in 1 until notRight.size) {
            if (notRight[i] != notRight[i - 1] + 1) {
                isSubsequent = false
                break
            }
        }

        if (isSubsequent) {
            println(1)
            return@repeat
        }

        println(2)
    }
}

fun df(a: IntArray): Pair<Triple<Long, Int, Int>, Triple<Long, Int, Int>> {

    var dif = 0L
    var lastIndex = 0
    var maxDif = 0L
    var maxIndex = 0
    var maxLength = 0
    for (i in 0 until a.size - 1 step 2) {
        dif += a[i + 1] - a[i]
        if (dif <= 0) {
            dif = 0
            lastIndex = i + 2
            continue
        }
        if (dif > maxDif) {
            maxDif = dif
            maxIndex = lastIndex
            maxLength = i + 2 - lastIndex
        }
    }

    var dif1 = 0L
    var lastIndex1 = 1
    var maxDif1 = 0L
    var maxIndex1 = 0
    var maxLength1 = 0
    for (i in 1 until a.size - 1 step 2) {
        dif1 += a[i + 1] - a[i]
        if (dif1 >= 0) {
            dif1 = 0
            lastIndex1 = i + 2
            continue
        }
        if (dif1 < maxDif1) {
            maxDif1 = dif1
            maxIndex1 = lastIndex1
            maxLength1 = i + 2 - lastIndex1
        }
    }

    return Pair(Triple(maxDif, maxIndex, maxLength), Triple(-maxDif1, maxIndex1, maxLength1))
}

data class MyPair(var first: Int, var second: Int) : Comparable<MyPair> {
    override fun compareTo(other: MyPair): Int {
        return this.first - other.first
    }

}

fun d() {
    val n = readInt()
    val a = readInts()

    var oddSum = 0L
    var evenSum = 0L

    for (i in 0 until n) {
        if (i % 2 == 0) {
            evenSum += a[i]
        } else {
            oddSum += a[i]
        }
    }

//    val maxOdd = oddSum + maxOf()
}

fun f() {
    val (n, m, q) = readInts()
    val a = Array(n) { IntArray(m) }

    val rows = LongArray(n)
    val columns = LongArray(m)

    for (i in 0 until n) {
        a[i] = readInts().toIntArray()

        for (j in 0 until m) {
            rows[i] = rows[i] + a[i][j]
            columns[j] = columns[j] + a[i][j]
        }
    }

    val rowsP = LongArray(n)
    val rowsS = LongArray(n)

    val rowsPM = LongArray(n)
    val rowsSM = LongArray(n)

    val columnsP = LongArray(m)
    val columnsS = LongArray(m)

    val columnsPM = LongArray(m)
    val columnsSM = LongArray(m)

    for (i in 0 until q + 1) {
        if (i != 0) {
            val (x, y, z) = readInts()
            val diff = z - a[x - 1][y - 1]
            rows[x - 1] = rows[x - 1] + diff
            columns[y - 1] = columns[y - 1] + diff
            a[x - 1][y - 1] = z
        }

        rowsP[0] = rows[0]
        for (j in 1 until n) {
            rowsP[j] = rowsP[j - 1] + rows[j]
            rowsPM[j] = rowsP[j - 1] + rowsPM[j - 1]
        }

        rowsS[n - 1] = rows[n - 1]
        for (j in n - 2 downTo 0) {
            rowsS[j] = rowsS[j + 1] + rows[j]
            rowsSM[j] = rowsS[j + 1] + rowsSM[j + 1]
        }

        columnsP[0] = columns[0]
        for (j in 1 until m) {
            columnsP[j] = columnsP[j - 1] + columns[j]
            columnsPM[j] = columnsP[j - 1] + columnsPM[j - 1]
        }

        columnsS[m - 1] = columns[m - 1]
        for (j in m - 2 downTo 0) {
            columnsS[j] = columnsS[j + 1] + columns[j]
            columnsSM[j] = columnsS[j + 1] + columnsSM[j + 1]
        }

        var minRow = minOf(rowsSM[0], rowsPM[n - 1])
        for (j in 1 until n - 1) {
            minRow = minOf(minRow, rowsSM[j] + rowsPM[j])
        }

        var minColumn = minOf(columnsSM[0], columnsPM[m - 1])
        for (j in 1 until m - 1) {
            minColumn = minOf(minColumn, columnsSM[j] + columnsPM[j])
        }

        print("${minRow + minColumn}\n")
    }
}

private inline fun sqr(x: Int) = 1L * x * x

val t = IntArray(2_200_000)

fun build(a: IntArray, v: Int, tl: Int, tr: Int) {
    if (tl == tr) {
        t[v] = a[tl]
    } else {
        val tm = (tl + tr) / 2
        build(a, v * 2, tl, tm)
        build(a, v * 2 + 1, tm + 1, tr)
        t[v] = t[v * 2] + t[v * 2 + 1]
    }

//    println("$v [$tl, $tr] = ${t[v]}")
}

fun update(v: Int, tl: Int, tr: Int, pos: Int): Int {
    if (tl == tr) {
        t[v]++
        return t[v]
    } else {
        val tm = (tl + tr) / 2
        val res = if (pos <= tm) {
            update(v * 2, tl, tm, pos)
        } else {
            update(v * 2 + 1, tm + 1, tr, pos)
        }
        t[v] = t[v * 2] + t[v * 2 + 1]
        return res
    }
}

fun delete(v: Int, tl: Int, tr: Int, pos: Int): Int {
//    println("$v [$tl, $tr] = ${t[v]}, pos = $pos")
    if (tl == tr) {
        t[v]--
        return tl
    } else {
        val tm = (tl + tr) / 2
        val res = if (pos <= t[v * 2]) {
            delete(v * 2, tl, tm, pos)
        } else {
            delete(v * 2 + 1, tm + 1, tr, pos - t[v * 2])
        }
        t[v] = t[v * 2] + t[v * 2 + 1]
        return res
    }
}

fun e() {
    val N = 1_00_000
    val f = IntArray(N)
    for (i in 0 until N) {
        f[i] = f[i / 10] + i % 10
    }

    val max = f.max()!!

//    println(max)

    repeat(readInt()) {
        val (n, k) = readInts()

        if (max * (k + 1) >= n) {
            var sum = 0
            for (i in 0 until k + 1) {
                sum += f[i]
            }

            if (n == sum) {
                println(0)
                return@repeat
            }

            for (i in 1 until N - k) {
                sum -= f[i - 1]
                sum += f[i + k]

                if (n == sum) {
                    println(i)
                    return@repeat
                }
            }
        }

        val res = StringBuilder()
        res.append('9')
        var sum = (9 - k..9).sum()

        println("$res $sum")

        while (sum < n) {
            res.append('9')
            sum += 9 * (k + 1)

            println("$res $sum")

            if (sum == n) {
                res[res.length - 1] = '9' - k
                println(res)
                return@repeat
            }
            if (sum > n) {
                sum -= 9 * (k + 1)
                for (i in 1 until 9) {
                    if (sum + i * (k + 1) == n) {
                        res[0] = '0' + i
                        res[res.length - 1] = '9' - k
                        println(res)
                        return@repeat
                    }
                }
                break
            }
        }

        println(-1)
    }
}

internal class FastScanner {
    var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))
    var st: StringTokenizer? = null

    operator fun next(): String {
        while (st == null || !st!!.hasMoreElements()) {
            try {
                st = StringTokenizer(br.readLine())
            } catch (e: IOException) {
                e.printStackTrace()
            }
        }
        return st!!.nextToken()
    }

    fun nextInt(): Int {
        return next().toInt()
    }
}

fun Int.isEven(): Boolean = this % 2 == 0
fun Int.isOdd(): Boolean = this % 2 == 1

public operator fun <T> List<T>.component6(): T {
    return get(5)
}

fun allPrimesUpTo(n: Int): List<Int> {
    val isPrime = BooleanArray(n + 1) { true }
    val primes = mutableListOf<Int>()

    isPrime[0] = false
    isPrime[1] = false
    for (i in 2 until n + 1) {
        if (isPrime[i]) {
            primes.add(i)

            if (i.toLong() * i > n)
                continue

            for (j in i * i until n + 1 step i) {
                isPrime[j] = false
            }
        }
    }

    return primes
}

fun leastDivisor(n: Int): Int {
    if (n % 2 == 0) return 2
    if (n % 3 == 0) return 3
    if (n % 5 == 0) return 5

    for (i in 7 until n) {
        if (i * i > n) break

        if (n % i == 0) {
            return i
        }
    }

    return 1
}


import java.lang.Integer.max
import kotlin.math.sqrt

fun main() {
    val t= readInt()
    repeat(t){
        val n = readInt()
        if(n%2==0){
            println("${n/2} ${n/2}")
        }
        else{
            val firstPrimeMultiple = findFirstPrimeMultiple(n)
            if(firstPrimeMultiple == n) println("${n-1} 1")
            else {
                val number = (n.div(firstPrimeMultiple))
                println("$number ${n-number}")
            }
        }
    }
}

fun findFirstPrimeMultiple(n: Int): Int{
    repeat(sqrt(n.toDouble()).toInt()+10){
        if(it >1) {
            val remaining = (n / it).toInt()
            if (remaining * it == n) return it
        }
    }
    return n
}

fun getNumber(row: Int, col: Int, n: Int, m: Int, cell: Int): Int {
    var number = 0
    if(row+1<n) number = number +1
    if (col+1<m) number = number +1
    if (row-1>=0) number = number +1
    if (col-1>=0) number = number +1
    return number
}

private fun isValid(row: Int, col: Int, n: Int, m: Int, cell: Int): Boolean {
    var number = 0
    if(row+1<n) number = number +1
    if (col+1<m) number = number +1
    if (row-1>=0) number = number +1
    if (col-1>=0) number = number +1
    return cell <=number
}

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
private fun readLongs() = readStrings().map { it.toLong() }


import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    val count = scan.nextInt()
    for (i in 0 until count) {
        val n = scan.nextLong()
        var divider = 2
        while (n % divider != 0L && divider <= n / divider.toFloat()) divider++
        val a = if (n % divider == 0L) n / divider else 1
        println("$a ${n - a}")
    }
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val t = sc.nextInt()
    for (_i in 0 until t) {
        val n = sc.nextInt()
        var p = -1
        var d = 2
        while (d * d <= n) {
            if (n % d == 0) {
                p = d
                break
            }
            d++
        }
        if (p == -1) p = n
        val v = n / p
        println("$v ${n - v}")
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


fun main() {
   var r : String = readLine()!!
    var q: String = readLine()!!
    var i : Int = 0;
    for(idx in 0..q.lastIndex) {
        if(q[idx] == r[i]) {
            i++;
        }
    }
    println(i + 1);
}


import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
import java.math.*;
import java.io.*;

fun main(args: Array<String>) {
 val s = Scanner(System.`in`)
 val postion = s.next();
 val instrution = s.next();
 colorstone(postion,instrution)
}
fun colorstone (postion : String ,instrution : String ){

val postions = postion.toCharArray();
val instrutions = instrution.toCharArray();
var counter = 1

 for(i in instrutions.indices){
if(postion[counter-1] == instrutions[i]){
    counter++
}
}
print(counter)
}


import java.util.*

fun main() {
    val sc = Scanner(System.`in`)
    var str = sc.nextLine()
    var cmd = sc.nextLine()
    var cnt = 1
    var i = 0
    for (ch in cmd) {
        if(ch == str[i]) {
            cnt++
            i++
        }
    }
    print(cnt)
}


import java.util.*

fun main() {
    val reader = Scanner(System.`in`)
    val t = reader.nextLine()
    val c = reader.nextLine()
    var ci=0
    c.forEach {
        if (it==t[ci]){
            ci++
        }
    }
    println(ci+1)
}


fun main() {
    val digitToOptions = listOf(2, 7, 2, 3, 3, 4, 2, 5, 1, 2)
//    print(readLine()!!.fold(1) { acc, c -> acc * digitToOptions[c - '0'] }) // A shorter alternative, less readable
    var sol = 1
    for (c in readLine()!!) sol *= digitToOptions[c - '0']
    print(sol)
}


fun main() {
    val a = readLine()!!
    var count = 0
    for (i in 0 until a.length-2) {
        for (j in i+1 until a.length-1) {
            for (k in j+1 until a.length) {
                if (a[i] == 'Q' && a[j] == 'A' && a[k] == 'Q') count++
            }
        }
    }
    println(count)
}


fun main(args: Array<String>) {
    val inStr= readLine()!!
    val aIndexes=inStr.withIndex().filter { (index, value)->value=='A' }
    val qIndexes=inStr.withIndex().filter { (index, value)->value=='Q' }
    var smileQantity=0
    for ((firstInd, firstA) in qIndexes){
        for((secondInd, secondQ) in aIndexes.filter { (index, value)->index>firstInd }){
            for((thirdInd, thirdA)in qIndexes.filter { (index, value)->index>secondInd }){
                smileQantity+=1
            }
        }
    }
    print(smileQantity)
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val s = sc.next()
    val n = s.length

    var count = 0
    for (i in 0 until n) {
        for (j in i + 1 until n) {
            for (k in j + 1 until n) {
                if (s[i].toString() + s[j] + s[k] == "QAQ") {
                    count += 1
                }
            }
        }
    }

    println(count)

}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val v = r.readLine()!!.split(" ").map { it.toInt() }
    val indexOfQ = mutableListOf<Int>()
    val indexOfA = mutableListOf<Int>()
    val str = r.readLine()!!
    val len = str.length
    val countQ = IntArray(len){0}
    val countA = IntArray(len){0}
    for (i in 0..len-1){
        when(str[i]){
            'Q' -> {
                indexOfQ += i
                indexOfA.forEach { countQ[it]++ }
            }
            'A' -> {
                indexOfA += i
                indexOfQ.forEach { countA[it]++ }
            }
        }
    }
    var ans = 0
    for (iq in indexOfQ){
        for (ia in indexOfA){
            if (ia>iq) ans += countQ[ia]
        }
    }

    println(ans)
}


import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.*
fun main(args: Array<String>) {

    val scanner = Scanner(System.`in`)
    for (i in 0 until 8) {
        val str = scanner.next()
        for (j in 0 until 8) {
            if (str[(j + 1) % 8] == str[j]) {
                println("NO")
                return
            }
        }
    }
    println("YES")

}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}
//class Pair(var a: Int, var b: Int): Comparable<Pair> {
//    override fun compareTo(other: Pair): Int {
//        return b - a - other.b + other.a
//    }
//}


import java.io.BufferedInputStream
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(BufferedInputStream(System.`in`))

    var ok = true
    for(i in 1..8){
        val row: String = scanner.next()
        ok = ok and isGood(row)
        if(!ok) break
    }

    if(ok) print("YES")
    else print("NO")

}

fun isGood(str: String): Boolean{
    var cur = 'X'
    for(c in str){
        if(cur == c) return false
        cur = c
    }
    return true
}


import java.util.*

fun main(args: Array<String>) {

    var sc = Scanner(System.`in`)
    var n = sc.nextInt()
    var x=0
    var max = 0
    for (i in 0 .. n-1){
        x=sc.nextInt()
        max= maxOf(x,max)
    }
    max = maxOf(0,max-25)
    println(max)
}


import java.io.IOException
import java.io.PrintWriter
import java.util.*;

fun main() {
    val scan = FastReader()
    val out = PrintWriter(System.out)

    var k = scan.nextInt()
    var ans = 0
    for(i in 1..k) ans = Math.max(ans, scan.nextInt())
    out.println(Math.max(0, ans - 25))

    out.close()
}

private class FastReader {
    var st: StringTokenizer? = null;

    fun next(): String {
        while(st == null || !st!!.hasMoreTokens()) {
            try {
                st = StringTokenizer(readLine()!!)
            }
            catch (e: IOException) {
                e.printStackTrace()
            }
        }
        return st!!.nextToken()
    }

    fun nextInt(): Int {
        return next().toInt()
    }

    fun nextLong(): Long {
        return next().toLong()
    }

    fun nextDouble(): Double {
        return next().toDouble()
    }

    fun nextLine(): String {
        var str = ""
        try {
            str = readLine()!!
        }
        catch (e : IOException) {
            e.printStackTrace()
        }
        return str
    }
}


import kotlin.math.max

fun main() {
    readInt()
    println(max(25, readInts().maxOrNull()!!) - 25)
}

// Input Reader
private fun readLn() = readLine()!!
private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


import kotlin.math.max

/* template start */
// input
private fun readString() = readLine()!!
private fun readStrings() = readString().split(" ")
private fun readInt() = readString().toInt()
private fun readDigits() = readString().map { it - '0' }
private fun readInts() = readStrings().map { it.toInt() }
private fun readLongs() = readStrings().map { it.toLong() }

// output
private fun <T> T.print(map: (T) -> String = { it.toString() }) = println(map(this))
private fun <T> Iterable<T>.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)
private fun <T> Array<T>.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)
private fun IntArray.print(sep: String? = null, map: ((Int) -> String)? = null) = asSequence().print(sep, map)
private fun <T> Sequence<T>.print(sep: String? = null, map: ((T) -> String)? = null) =
    println(joinToString(sep ?: "", transform = map ?: { it.toString() }))

// others
private val Int.isEven: Boolean get() = this % 2 == 0
private val Int.isOdd: Boolean get() = !this.isEven
private fun queries(block: (Int) -> Unit) = repeat(readInt(), block)

/* template end */

fun main() {
    val n = readInt()
    val maxRank = readInts().max()!!
    println(max(0, maxRank - 25))
}


import java.math.BigInteger

fun main(args: Array<String>) {
    val sb = StringBuilder()
    val nums = Array(10, { i-> BigInteger("$i") })
    val FOUR = nums[4]
    var x = BigInteger(readLine())
    do {
        val divideAndRemainder = x.divideAndRemainder(BigInteger.TEN)
        val div = divideAndRemainder[0]
        val rem = divideAndRemainder[1]
        if (div == BigInteger.ZERO) {
            var num:BigInteger
            if (rem.toInt() != 9) {
                num = if (rem > FOUR) nums[9 - rem.toInt()] else rem
            } else {
                num = rem
            }
            sb.insert(0, num)
            println(sb)
            return
        } else {
            val num = if (rem > FOUR) nums[9 - rem.toInt()] else rem
            sb.insert(0, num)
        }
        x = div
    } while (true)
}


import java.util.*

fun main(args: Array<String>){
    //val ( n, m ) = readLine()!!.split(' ').map(String::toInt)
    var s = readLine()!!
    print( if( s[0] >= '5' && s[0] != '9' ) '9' - s[0] else s[0] )
    s = s.removeRange(0, 1)
    for( i in s ){
        print( if ( i >= '5' ) '9' - i else i )
    }
}


import java.util.*

fun min(a:Double,b:Double) = if (a<b) a else b
fun max(a:Double,b:Double) = if (a>b) a else b
fun min(a:Int,b:Int) = if (a<b) a else b
fun max(a:Int,b:Int) = if (a>b) a else b
fun printD(d: Double) { print(d) }
fun printI(d:Int) { print(d) }
fun printS(d: String) { print(d) }
fun printL(d: Long) { print(d) }
fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readInts()  = readLn().split(" ").map{it.toInt()}
fun readLong() = readLn().toLong()
class pair (var first:Int, var second:Int)

fun solve() {
   val cin = Scanner(System.`in`)

   /*
   map[q] <=> map.getOrDefault(q,0)
   Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));
   print("${k[i].second}"); - вывод аргумента пары
   var m=ArrayList<int> (); <=> vector
   getline(cin,a) <=> readLine()!!.last()

  readInt() - одно число
  readInts() - несколько чисел

   */

    /* --------- */

 var (a,b)=readInts();
 var q=readInts();
 var sum=0;
 var max1=0;
 for (i in q) {
 max1=max(max1,i); sum+=i; }
 if (b>=sum-max1) print("YES"); else print("NO");
   /* --------- */

}

    fun main() {
    val cin = Scanner(System.`in`)

    var T=1;
    //T=readLine()!!.toInt();

    for (i55555 in 1..T) solve()
}


import java.util.*

fun main(args: Array<String>) = with(Scanner(System.`in`), {
    var (n, s) = readLine()!!.split(" ").map { it.toInt() }
    var mx = 0
    var sum = 0
    for (i in 1..n) {
        sum += nextInt().apply { mx = Math.max(mx, this) }
    }
    if (sum - mx <= s) print("YES") else print("NO")
})


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main() {

    fun summ(n: Int): Int {
        return n * (n + 1) / 2
    }
    fun len(nn: Int): Int {
        var n = nn
        var res = 0
        while(n > 0) {
            res++
            n /= 10
        }
        return res
    }

    var T = readInt()
    while(T-->0) {
        var num = readInt()
        var less = (num%10)-1
        var res = summ(4) * less
        res += summ(len(num))

        println(res)
    }

}