from collections import defaultdict n = int(input()) a = list(map(int, input().split())) MOD = 998244353 res = 0 d = defaultdict(int) for i in range(n): c = d[a[i] - 1] res += c nc = (d[a[i]] + c + 1) % MOD d[a[i]] = nc print(res % MOD)