object Main extends App {
  val n =  scala.io.StdIn.readInt()
  val d = scala.io.StdIn.readLine()
  val dArray = d.split(" ").map(_.toLong).toVector
  if(dArray(0) != 0L) {
    println(0)
  } else {
    var before = 0L
    println(dArray.tail.foldLeft(1L) { case (sum, d) =>
      if ( d == 0L) {
        sum * 0L
      } else if (before != 0L && before < d) {
        sum * 0L
      } else {
        before = d
        sum * d % 998244353L
      }
    })
  }
}