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 dp[a] = dp.get(a, 0) + x + 1 print(ans % MOD)