MOD = 998244353 n = int(input()) A = list(map(int, input().split())) dp = {} ans = 0 for a in A: x = dp.get(a - 1, 0) ans += x ans %= MOD dp[a] = (dp.get(a, 0) + x + 1) % MOD print(ans % MOD)