#include <bits/stdc++.h>

const int N = 405;
const int mod = 998244353;
int len[N], c[N][N], ex[N], f[N][N], g[N][N], tf[N], tg[N], h[N];
int n, T, rt;

inline void add(int &x, int y)
{
	x += y;
	x >= mod ? x -= mod : 0;
}

inline void dec(int &x, int y)
{
	x -= y;
	x < 0 ? x += mod : 0;
}

inline void Update(int now, int x)
{
	for (int i = 0; i <= len[x] + len[now]; ++i)
		tf[i] = tg[i] = 0;
	for (int i = 0; i <= len[x]; ++i)
		for (int j = 0; j <= len[now]; ++j)
		{
			tf[i + j] = (1ll * f[x][i] * f[now][j] + tf[i + j]) % mod;
			tg[i + j] = (1ll * g[x][i] * g[now][j] + tg[i + j]) % mod;
		}
	len[now] += len[x];
	for (int i = 0; i <= len[now]; ++i)
		f[now][i] = tf[i], g[now][i] = tg[i];
}

inline int solve(int l, int r, int lst)
{
	if (l > r)
		return 0;
	
	int mid = l, now = ++T;
	for (int i = l + 1; i <= r; ++i)
		if (h[i] < h[mid])
			mid = i;

	int lc = solve(l, mid - 1, h[mid]),
		rc = solve(mid + 1, r, h[mid]);
	f[now][0] = g[now][0] = len[now] = 1;
	if (lc)	
		Update(now, lc);
	if (rc)
		Update(now, rc);
	int _len = len[now];
	for (int i = 1; i <= h[mid] - lst; ++i)
	{
		for (int j = 0; j <= _len; ++j)
			tf[j] = tg[j] = 0;
		if (i == 1)
		{
			int delta = 0;
			for (int j = l; j <= r; ++j)
				if (h[j] == h[mid])
					++delta;
			_len -= delta;
			for (int j = 0; j <= _len; ++j)
			{
				tf[j + delta] = (1ll * f[now][j] * (ex[j] - 1) + tf[j + delta]) % mod;
				tg[j] = (1ll * g[now][j] * (ex[j] - 1) + tg[j]) % mod;

				add(tf[j], g[now][j]);
				add(tg[j], g[now][j]);
				for (int a = 0; j + a <= _len; ++a)
					for (int b = 0; b <= delta; ++b)
						if (a + b > 0)
						{
							int tmp = 1ll * c[_len - j][a] * c[delta][b] % mod * ex[j] % mod;
							tf[j + a + delta] = (1ll * tmp * f[now][j] + tf[j + a + delta]) % mod;
							tg[j + a + b] = (1ll * tmp * g[now][j] + tg[j + a + b]) % mod;
						}
			}
			_len += delta;
		}
		else
		{
			for (int j = 0; j <= _len; ++j)
			{
				tf[j] = (1ll * f[now][j] * (ex[j] - 1) + tf[j]) % mod;
				tg[j] = (1ll * g[now][j] * (ex[j] - 1) + tg[j]) % mod;		

				add(tf[j], g[now][j]);
				add(tg[j], g[now][j]);

				for (int k = 1; j + k <= _len; ++k)
				{
					tf[j + k] = (1ll * f[now][j] * c[_len - j][k] % mod * ex[j] + tf[j + k]) % mod;
					tg[j + k] = (1ll * g[now][j] * c[_len - j][k] % mod * ex[j] + tg[j + k]) % mod;
				}
			}
		}
		for (int j = 0; j <= _len; ++j)
			f[now][j] = tf[j], g[now][j] = tg[j];
	}
	return now;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &h[i]);

	ex[0] = 1;
	for (int i = 1; i <= n; ++i)
		add(ex[i] = ex[i - 1], ex[i - 1]);
	c[0][0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		c[i][0] = 1;
		for (int j = 1; j <= i; ++j)
			add(c[i][j] = c[i - 1][j - 1], c[i - 1][j]);
	}

	rt = solve(1, n, 0);
	printf("%d\n", f[rt][n]);
}