MOD = 998244353i64 n = read_line.to_i a = read_line.split.map(&.to_i) count = Hash(Int32, Int64).new { |h, k| h[k] = 0i64 } n.times do |i| v = a[i] count[v] = (count[v] + count[v - 1] + 1) % MOD end puts (count.values.sum - n) % MOD