from collections import Counter import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 n = ii() a = li() dp = Counter() for v in a: dp[v] += 1 dp[v] += dp[v - 1] dp[v] %= mod ans = -n for v, c in dp.items(): ans += c ans %= mod print(ans)