N = int(input()) A = list(map(int, input().split())) MOD = 998244353 MIN = [] for i in range(N): MIN.append(10**5-A[i]) for i in reversed(range(N-1)): MIN[i] = min(MIN[i], MIN[i+1]) dp = [[0]*(MIN[-1]+1) for _ in range(N)] for i in range(MIN[0]+1): dp[0][i] = 1 if N >= 2: for i in range(1, MIN[-1]+1): dp[0][i] += dp[0][i-1] dp[0][i] %= MOD for i in range(1, N): if A[i-1] <= A[i]: left = 0 else: left = A[i-1]-A[i] for j in range(left, MIN[i]+1): if A[i-1] <= A[i]: dp[i][j] = dp[i-1][j] else: dp[i][j] = dp[i-1][j-left] if i+1 < N: for j in range(1, MIN[-1]+1): dp[i][j] += dp[i][j-1] dp[i][j] %= MOD print(sum(dp[-1])%MOD)