The sequence of integers $a_1, a_2, \dots, a_k$ is called a good array if $a_1 = k - 1$ and $a_1 > 0$. For example, the sequences $[3, -1, 44, 0], [1, -99]$ are good arrays, and the sequences $[3, 7, 8], [2, 5, 4, 1], [0]$ — are not.

A sequence of integers is called good if it can be divided into a positive number of good arrays. Each good array should be a subsegment of sequence and each element of the sequence should belong to exactly one array. For example, the sequences $[2, -3, 0, 1, 4]$, $[1, 2, 3, -3, -9, 4]$ are good, and the sequences $[2, -3, 0, 1]$, $[1, 2, 3, -3 -9, 4, 1]$ — are not.

For a given sequence of numbers, count the number of its subsequences that are good sequences, and print the number of such subsequences modulo 998244353.


-----Input-----

The first line contains the number $n~(1 \le n \le 10^3)$ — the length of the initial sequence. The following line contains $n$ integers $a_1, a_2, \dots, a_n~(-10^9 \le a_i \le 10^9)$ — the sequence itself.


-----Output-----

In the single line output one integer — the number of subsequences of the original sequence that are good sequences, taken modulo 998244353.


-----Examples-----
Input
3
2 1 1

Output
2

Input
4
1 1 1 1

Output
7



-----Note-----

In the first test case, two good subsequences — $[a_1, a_2, a_3]$ and $[a_2, a_3]$.

In the second test case, seven good subsequences — $[a_1, a_2, a_3, a_4], [a_1, a_2], [a_1, a_3], [a_1, a_4], [a_2, a_3], [a_2, a_4]$ and $[a_3, a_4]$.

Source: codeforces | Difficulty: HARD
Tags: Dynamic programming

Combinatorics


Solutions:
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 33, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
s = Combination(mod1)
l = list(map(int, input().split()))
dp = [0 for i in range(n + 1)]
s1 = SegmentTree(dp)
for i in range(n - 2, -1, -1):
	for j in range(n - 1, i, -1):
		ch = j - i - 1
		d = l[i] - 1
		dp[i] += (s1.query(j + 1, n) + 1) * s.ncr(ch, d)
		dp[i] %= mod1
	s1.__setitem__(i, dp[i])
print(sum(dp) % mod1)


MOD = 998244353
n = int(input())
d = [0] * n
a = list(map(int, input().split()))
for i in range(n - 2, -1, -1):
	if a[i] <= 0:
		continue
	cur_cnk = 1
	cur_k = a[i]
	cur_n = a[i]
	for j in range(i + a[i] + 1, n):
		d[i] = (d[i] + d[j] * cur_cnk % MOD) % MOD
		cur_cnk *= cur_n + 1
		cur_cnk //= cur_n + 1 - cur_k
		cur_n += 1
	if i + a[i] + 1 <= n:
		d[i] = (d[i] + cur_cnk) % MOD
ans = 0
for i in range(n):
	ans = (ans + d[i]) % MOD
print(ans)


import sys
input = sys.stdin.readline
N = 10 ** 4 + 10
mod = 998244353
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inv.append(-inv[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inv[-1] % mod)

def comb(m, r, mod):
	if r < 0 or r > m:
		return 0
	return g1[m] * g2[r] * g2[m - r] % mod
n = int(input())
a = [0] + list(map(int, input().split()))
dp = [0] * (n + 2)
dp[n + 1] = 1
for i in range(1, n + 1)[::-1]:
	if a[i] <= 0:
		continue
	for j in range(i + a[i] + 1, n + 2):
		dp[i] += dp[j] * comb(j - i - 1, a[i], mod) % mod
		dp[i] %= mod
print(sum(dp[:-1]) % mod)


n = int(input())
m = 998244353
dl = [1] + [0] * n
for i in map(int, input().split()):
	v = dl[:]
	if 0 < i < n:
		v[i] = (v[i] + v[0]) % m
	for j in range(n):
		v[j] = (v[j] + dl[j + 1]) % m
	dl = v
print((dl[0] - 1) % m)


N = int(input())
a = [0] + list(map(int, input().split()))
mod = 998244353
dp = [[0 for i in range(N + 2)] for i in range(N + 1)]
for i in range(1, N + 1):
	for j in range(N + 1):
		dp[i][j] = (dp[i - 1][j] + dp[i - 1][j + 1]) % mod
	if a[i] <= N and a[i] > 0:
		dp[i][a[i]] = (dp[i][a[i]] + dp[i - 1][0] + 1) % mod
print(dp[N][0])


m = 998244353
n = int(input())
u = [1] + [0] * n
for a in map(int, input().split()):
	v = u[:]
	if 0 < a < n:
		v[a] += u[0]
	for j in range(n):
		v[j] = (v[j] + u[j + 1]) % m
	u = v
print((u[0] - 1) % m)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(200001)]
pp = [0] * 200001

def SieveOfEratosthenes(n=200000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
n = int(input())
m = 998244353
dp = [1] + [0] * n
for j in map(int, input().split()):
	v = dp[:]
	if 0 < j < n:
		v[j] = (v[j] + v[0]) % m
	for k in range(n):
		v[k] = (v[k] + dp[k + 1]) % m
	dp = v
print((dp[0] - 1) % m)


from functools import lru_cache
mod = 998244353

@lru_cache(maxsize=None)
def fact(k):
	global mod
	res = 1
	for i in range(1, k + 1):
		res *= i
		res %= mod
	return res

def nck(n, k):
	global mod
	res = fact(n)
	res *= pow(fact(n - k), mod - 2, mod)
	res *= pow(fact(k), mod - 2, mod)
	res %= mod
	return res
n = int(input())
a = list(map(int, input().split()))
dp = [0] * n + [1]
for i in range(n - 1, -1, -1):
	if a[i] <= 0:
		continue
	for j in range(i + a[i] + 1, n + 1):
		dp[i] += nck(j - i - 1, a[i]) * dp[j]
		dp[i] %= mod
print((sum(dp) - 1) % mod)


import sys, math, queue
MOD = 998244353
sys.setrecursionlimit(1000000)

def ncr(n, r):
	global f
	return f[n] * pow(f[r], MOD - 2, MOD) * pow(f[n - r], MOD - 2, MOD) % MOD
n = int(input())
a = list(map(int, input().split()))
dp = [0 for i in range(n)]
f = [1]
for i in range(1, n + 1):
	f.append(f[-1] * i % MOD)
for i in range(n):
	if i + a[i] < n and a[i] > 0:
		dp[i] = ncr(n - 1 - i, a[i])
for i in reversed(range(n)):
	if a[i] <= 0:
		continue
	for j in range(i + a[i] + 1, n):
		dp[i] = (dp[i] + ncr(j - 1 - i, a[i]) * dp[j]) % MOD
print(sum(dp) % MOD)


n = int(input())
s = list(map(int, input().split()))
mod = 998244353
cm = [[0 for i in range(n + 2)] for j in range(n + 2)]
for i in range(n + 2):
	cm[i][0] = 1
for i in range(1, n + 2):
	for j in range(1, n + 2):
		cm[i][j] = cm[i - 1][j] + cm[i - 1][j - 1]
		cm[i][j] = cm[i][j] % mod
dp = [0 for i in range(n + 2)]
acum = [0 for i in range(n + 2)]
for i in range(n - 1, -1, -1):
	acum[i] = acum[i + 1]
	if s[i] <= 0:
		continue
	for j in range(i + s[i], n):
		dp[i] = (cm[j - (s[i] + i) + s[i] - 1][s[i] - 1] + cm[j - (s[i] + i) + s[i] - 1][s[i] - 1] * acum[j + 1] + dp[i]) % mod
	acum[i] = (dp[i] + acum[i]) % mod
print(acum[0])


mod = 998244353

def ncr(n, r):
	if n < r or n == 0:
		return 0
	if r == 0:
		return 1
	return fac[n] * invfac[r] * invfac[n - r] % mod
n = int(input())
a = list(map(int, input().split()))
fac = [1] * (n + 1)
invfac = [1] * (n + 1)
for i in range(1, n + 1):
	fac[i] = i * fac[i - 1] % mod
	invfac[i] = pow(fac[i], mod - 2, mod)
dp = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	if a[i] > 0:
		for j in range(min(n, i + a[i] + 1), n):
			dp[i] = (dp[i] + dp[j] * ncr(j - i - 1, a[i])) % mod
		dp[i] = (dp[i] + ncr(n - i - 1, a[i])) % mod
print(sum(dp) % mod)


from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque

def read():
	return int(input())

def readmap():
	return map(int, input().split())

def readlist():
	return list(map(int, input().split()))
MAX = 10000
MOD = 998244353
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def COMinit():
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, MAX):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD
	return None

def COM(n, k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
N = read()
A = readlist()
for i in range(N):
	A[i] = max(0, A[i])
	if A[i] > N - i - 1:
		A[i] = 0
COMinit()
dp = [0] * N
for n in range(1, N):
	dp[n] = dp[n - 1]
	for i in range(n):
		if i == 0:
			dp[n] = (dp[n] + COM(n - i - 1, A[i] - 1)) % MOD
		else:
			dp[n] = (dp[n] + COM(n - i - 1, A[i] - 1) * (dp[i - 1] + 1)) % MOD
print(dp[N - 1])


n = int(input())
arr = list(map(int, input().split()))
mod = 998244353
dp = [0] * (n + 2)
C = [[0] * (n + 2) for i in range(n + 2)]
for i in range(0, n + 1):
	C[i][0] = 1
	for j in range(1, i + 1):
		C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
ans = 0
dp[n] = 1
for iter in range(0, n):
	i = n - iter - 1
	if arr[i] <= 0:
		continue
	for j in range(i + arr[i] + 1, n + 1):
		dp[i] += dp[j] * C[j - i - 1][arr[i]]
		dp[i] %= mod
	ans += dp[i]
print(ans % mod)


n = int(input())
g = 998244353
dp = [1] + [0] * n
for i in map(int, input().split()):
	v = dp[:]
	if 0 < i < n:
		v[i] = (v[i] + v[0]) % g
	for j in range(n):
		v[j] = (v[j] + dp[j + 1]) % g
	dp = v
print((dp[0] - 1) % g)


n = int(input())
m = 998244353
dp = [1] + [0] * n
for j in map(int, input().split()):
	v = dp[:]
	if 0 < j < n:
		v[j] = (v[j] + v[0]) % m
	for k in range(n):
		v[k] = (v[k] + dp[k + 1]) % m
	dp = v
print((dp[0] - 1) % m)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def ctd(chr):
	return ord(chr) - ord('a')
mod = 998244353
INF = float('inf')

def main():
	n = N()
	arr = RLL()
	cb = [[0] * (n + 1) for _ in range(n + 1)]
	for i in range(n + 1):
		for j in range(i + 1):
			if j == 0 or j == n:
				cb[i][j] = 1
			else:
				cb[i][j] = (cb[i - 1][j] + cb[i - 1][j - 1]) % mod
	dp = [0] * (n + 1)
	dp[-1] = 1
	for i in range(n - 1, -1, -1):
		for j in range(i + 1, n + 1):
			if j - 1 - i >= arr[i] and arr[i] > 0:
				dp[i] += cb[j - 1 - i][arr[i]] * dp[j] % mod
	res = 0
	for i in dp[:-1]:
		res += i % mod
	print(res % mod)
main()


import sys
zz = 1
sys.setrecursionlimit(10 ** 5)
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def ii():
	return input().rstrip()

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
uu = t

def ncr(n, r):
	if n < r or n == 0:
		return 0
	if r == 0:
		return 1
	return fac[n] * invfac[r] * invfac[n - r] % mod
while t > 0:
	t -= 1
	n = fi()
	a = li()
	mod = 998244353
	dp = [0] * (n + 1)
	fac = [1] * (n + 1)
	invfac = [1] * (n + 1)
	for i in range(1, n + 1):
		fac[i] = i * fac[i - 1] % mod
		invfac[i] = pow(fac[i], mod - 2, mod)
	for i in range(n - 1, -1, -1):
		if a[i] > 0:
			for j in range(min(n, i + a[i] + 1), n):
				dp[i] = (dp[i] + dp[j] * ncr(j - i - 1, a[i])) % mod
			dp[i] = (dp[i] + ncr(n - i - 1, a[i])) % mod
	print(sum(dp) % mod)


n = int(input())
a = list(map(int, input().split()))
mod = 998244353

def pow_(x, p, mod):
	if p == 1:
		return x % mod
	tmp = pow_(x, p // 2, mod)
	if p % 2 == 0:
		return tmp * tmp % mod
	else:
		return tmp * tmp * x % mod

def reverse(x, mod):
	return pow_(x, mod - 2, mod)

def create_gt(gt):
	for i in range(2, len(gt)):
		gt[i] = gt[i - 1] * i % mod

def kCn(k, n, mod):
	return gt[n] * reverse(gt[k], mod) * reverse(gt[n - k], mod) % mod

def create_kcn(N, mod):
	kcn = [[0] * N for _ in range(N)]
	kcn[0][0] = 1
	for n in range(1, N):
		for k in range(n, -1, -1):
			kcn[k][n] = (kcn[k - 1][n - 1] + kcn[k][n - 1]) % mod
	return kcn
kcn = create_kcn(1001, mod)
dp = [-1] * n
for i in range(n - 2, -1, -1):
	if a[i] > 0 and i + a[i] < n:
		temp = 0
		for j in range(i + a[i] + 1, n):
			if dp[j] > 0:
				temp = (temp + dp[j] * kcn[a[i]][j - i - 1]) % mod
		temp = (temp + kcn[a[i]][n - i - 1]) % mod
		dp[i] = temp
print(sum([x for x in dp if x > 0]) % mod)


N = 1009
MOD = 998244353
a = [0] * N
dp = [0] * N
C = []
for i in range(0, N):
	C.append([0] * N)
for i in range(0, N):
	C[i][0] = 1
	C[i][i] = 1
	for j in range(1, i):
		C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD
n = int(input())
b = input().split()
for i in range(0, n):
	a[i] = int(b[i])
dp[n] = 1
for i in range(n - 1, -1, -1):
	if a[i] <= 0:
		continue
	for j in range(i + a[i] + 1, n + 1):
		dp[i] += dp[j] * C[j - i - 1][a[i]] % MOD
		dp[i] %= MOD
soma = 0
for i in range(0, n):
	soma += dp[i]
	soma %= MOD
print(soma)


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
N = 10001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans
p = 998244353
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
n = int(input())
b = list(map(int, input().split()))
b.reverse()
dp = [[0, 0] for i in range(n + 1)]
dp[0][1] = 1
for i in range(1, n + 1):
	if i > 1:
		dp[i][0] = sum(dp[i - 1]) % p
	if b[i - 1] <= 0:
		pass
	else:
		j = 0
		while j < i:
			l = i - j
			if l >= b[i - 1] + 1:
				dp[i][1] += dp[j][1] * Binomial(l - 1, b[i - 1], p) % p
			j += 1
print(sum(dp[-1]) % p)


from random import randint

def factMod(n, mod):
	res = 1
	for i in range(2, n + 1):
		res = res * i % mod
	return res

def powMod(n, p, mod):
	res = 1
	while p > 0:
		if p % 2 == 1:
			res = res * n % mod
		p //= 2
		n = n * n % mod
	return res

def invMod(n, mod):
	return powMod(n, mod - 2, mod)

def CnkMod(n, k, mod):
	return factMod(n, mod) * invMod(factMod(k, mod) * factMod(n - k, mod), mod) % mod

def computeCnksMod(N, mod):
	res = [[0] * (N + 1) for i in range(N + 1)]
	res[0][0] = 1
	for n in range(1, N + 1):
		res[n][0] = res[n - 1][0]
		for k in range(1, n + 1):
			res[n][k] = (res[n - 1][k] + res[n - 1][k - 1]) % mod
	return res
magic = 998244353
n = int(input()) + 1
aa = [1] + [int(s) + 1 for s in input().split(' ')]
cnks = computeCnksMod(n, magic)
d = [0] * (n + 1)
d[n] = 1
for i in reversed(list(range(n))):
	if i != 0 and aa[i] < 2:
		continue
	cur = 0
	tosel = aa[i] - 1
	for j in range(i + tosel + 1, n + 1):
		avail = j - i - 1
		cur = (cur + cnks[avail][tosel] * d[j]) % magic
	d[i] = cur
print(d[0] - 1)


import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
print = lambda x: os.write(1, str(x).encode())
MOD = 998244353
MAGIC = 6755399441055744.0
MODF = float(MOD)
SHRT = 65536.0
MODF_INV = 1.0 / MODF
SHRT_INV = 1.0 / SHRT
fround = lambda x: x + MAGIC - MAGIC
fmod = lambda a: a - MODF * fround(MODF_INV * a)
fmul = lambda a, b, c=0.0: fmod(fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c)

def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	cache = [[0.0] * (n + 1) for _ in range(n + 1)]
	dp = [-1.0] * n

	def nCk(n, k):
		if not 0 <= k <= n:
			return 0.0
		if n == k or k == 0:
			return 1.0
		if cache[n][k] == 0.0:
			cache[n][k] = fmod(nCk(n - 1, k) + nCk(n - 1, k - 1))
		return cache[n][k]

	def solve(i):
		if i == n:
			return 1.0
		if a[i] <= 0:
			return 0.0
		if dp[i] == -1.0:
			dp[i] = fmod(sum((fmul(nCk(j - i - 1, a[i]), solve(j)) for j in range(i + a[i] + 1, n + 1))))
		return dp[i]
	print(int(fmod(sum((solve(i) for i in range(n - 1, -1, -1))))) % MOD)
main()


3
MOD = 998244353

def solve(N, A):
	dp = [[0] * N for _ in range(N + 1)]
	dp[0][0] = 1
	for i in range(N):
		for j in range(N):
			c = dp[i][j]
			dp[i + 1][j] += c
			dp[i + 1][j] %= MOD
			if j == 0:
				if A[i] > 0 and A[i] < N:
					dp[i + 1][A[i]] += c
					dp[i + 1][A[i]] %= MOD
			else:
				dp[i + 1][j - 1] += c
				dp[i + 1][j - 1] %= MOD
	return (dp[N][0] + MOD - 1) % MOD

def main():
	N = int(input())
	A = [int(e) for e in input().split(' ')]
	assert len(A) == N
	print(solve(N, A))

def __starting_point():
	main()
__starting_point()


import sys
from array import array

def readline():
	return sys.stdin.buffer.readline().decode('utf-8')
(max_n, mod) = (10 ** 5, 998244353)
(fac, inv) = ([1] * max_n, [1] * max_n)
for i in range(2, max_n):
	fac[i] = fac[i - 1] * i % mod
inv[-1] = pow(fac[-1], mod - 2, mod)
for i in range(max_n - 1, 0, -1):
	inv[i - 1] = inv[i] * i % mod
n = int(readline())
a = list(map(int, readline().split()))
dp = array('i', [0]) * (n + 1)
for (i, x) in enumerate(a):
	if x < 1:
		continue
	for j in range(i + x + 1, n + 1):
		dp[j] = (dp[j] + (dp[i] + 1) * fac[j - i - 1] * inv[x] * inv[j - i - 1 - x]) % mod
print(dp[-1])


from sys import stdin, stdout
get_string = lambda : stdin.readline().strip('\n')
get_intmap = lambda : map(int, get_string().split(' '))

def ncr_generator(n, r):
	ncrr = 1
	while True:
		yield ncrr
		n += 1
		ncrr = ncrr * n // (n - r)

def testcase():
	n = int(input())
	a = tuple(get_intmap())
	m = 998244353
	dp = [0] * (n + 1)
	dp[n] = 1
	for i in range(n - 1, -1, -1):
		ai = a[i]
		if ai <= 0:
			continue
		for (j, ncrr) in zip(range(i + ai + 1, n + 1), ncr_generator(ai, ai)):
			dp[i] = (dp[i] + ncrr * dp[j]) % m
	ans = 0
	for i in dp[:-1]:
		ans = (ans + i) % m
	print(ans)
testcase()


mod = 998244353
n = int(input())
a = list(map(int, input().split()))
c = [[1] * n for _ in range(n)]
for i in range(n):
	for j in range(1, i // 2 + 1):
		c[i][i - j] = c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod
d = [0] * n + [1]
for i in range(n - 1, -1, -1):
	if a[i] <= 0:
		continue
	for j in range(i + a[i] + 1, n + 1):
		d[i] += d[j] * c[j - i - 1][a[i]]
	d[i] %= mod
print((sum(d) - 1) % mod)


mod = 998244353
n = int(input())
a = list(map(int, input().split()))

class Combi:

	def __init__(self, N, mod):
		self.power = [1 for _ in range(N + 1)]
		self.rev = [1 for _ in range(N + 1)]
		self.mod = mod
		for i in range(2, N + 1):
			self.power[i] = self.power[i - 1] * i % self.mod
		self.rev[N] = pow(self.power[N], self.mod - 2, self.mod)
		for j in range(N, 0, -1):
			self.rev[j - 1] = self.rev[j] * j % self.mod

	def C(self, K, R):
		if K < R:
			return 0
		else:
			return self.power[K] * self.rev[K - R] * self.rev[R] % self.mod

	def P(self, K, R):
		if K < R:
			return 0
		else:
			return self.power[K] * self.rev[K - R] % self.mod
c = Combi(10000, mod)
dp = [0] * 5000
for l in range(n - 1, -1, -1):
	v = a[l]
	if v > 0:
		dp[l] = sum((c.C(x - l - 2, v - 1) * (1 + dp[x]) for x in range(l, n + 1))) % mod
	dp[l] += dp[l + 1]
	dp[l] %= mod
ans = dp[0] % mod
print(ans)


def computeCnksMod(N, mod):
	res = [[0] * (N + 1) for i in range(N + 1)]
	res[0][0] = 1
	for n in range(1, N + 1):
		res[n][0] = res[n - 1][0]
		for k in range(1, n + 1):
			res[n][k] = (res[n - 1][k] + res[n - 1][k - 1]) % mod
	return res
magic = 998244353
n = int(input()) + 1
aa = [1] + [int(s) + 1 for s in input().split(' ')]
cnks = computeCnksMod(n, magic)
d = [0] * (n + 1)
d[n] = 1
for i in reversed(list(range(n))):
	if i != 0 and aa[i] < 2:
		continue
	cur = 0
	tosel = aa[i] - 1
	for j in range(i + tosel + 1, n + 1):
		avail = j - i - 1
		cur = (cur + cnks[avail][tosel] * d[j]) % magic
	d[i] = cur
print(d[0] - 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def getc(s):
	c = 0
	for i in range(len(s) - 7, -1, -1):
		st = 'abacaba'
		if s[i:i + 7] == st:
			c += 1
	return c
max_n = 2 * 10 ** 5
mod = 998244353
(fact, inv_fact) = ([0] * (max_n + 1), [0] * (max_n + 1))
fact[0] = 1
for i in range(max_n):
	fact[i + 1] = fact[i] * (i + 1) % mod
inv_fact[-1] = pow(fact[-1], mod - 2, mod)
for i in reversed(range(max_n)):
	inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod

def nCr_mod(n, r):
	res = 1
	while n or r:
		(a, b) = (n % mod, r % mod)
		if a < b:
			return 0
		res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
		n //= mod
		r //= mod
	return res
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [0] * n
	for i in range(n - 1, -1, -1):
		if a[i] < 1:
			continue
		if n - i - 1 >= a[i]:
			dp[i] = nCr_mod(n - i - 1, a[i])
		for j in range(i + a[i] + 1, n - 1):
			spaces = j - i - 1
			comb = nCr_mod(spaces, a[i])
			dp[i] += comb * dp[j]
	print(sum(dp) % mod)