N = gets.to_i P = gets.split.map(&:to_i) MOD = 998_244_353 pos = Hash.new P.each_with_index do |v, i| pos[v] = i end l = Float::INFINITY r = -Float::INFINITY ans = 1 0.upto(N - 1) do |x| i = pos[x] if (l..r).cover?(i) ans *= (r - l - x + 1) ans %= MOD else l = i if l > i r = i if r < i end end puts ans