N = gets.to_i A = gets.split.map(&:to_i) MOD = 998_244_353 counter = Hash.new(0) ans = 0 A.each do |a| ans += counter[a - 1] ans %= MOD counter[a] += counter[a - 1] + 1 counter[a] %= MOD end puts ans