N = int(input()) A = list(map(int, input().split())) MOD = 998244353 dp = {} for a in A: if a in dp: dp[a] = (dp[a]+1) % MOD else: dp[a] = 1 # if a+1 in dp: # dp[a]=(dp[a+1]+dp[a])%MOD if a-1 in dp: dp[a] = (dp[a-1]+dp[a]) % MOD ans = -N for k in dp: ans = (ans+dp[k]) % MOD print(ans)