#include<vector>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>

using namespace std;

//int mod = 998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<vector<int>>vvi;
typedef vector<vector<ll>>vvl;
typedef vector< pair<ll, ll>>vpll;
typedef vector< pair<ld, ld>>vpld;
typedef pair<ld, ld>pld;
#define mp make_pair
#define pb push_back

int mod=998244353;
int sum(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}
int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}
int mlt(int a, int b)
{
	ll c = a * 1LL * b;
	return c % mod;
}
int ibit(int n, int i)
{
	return ((n >> i) & 1);
}
int pow2[555], c[555][555];
vi layer(vi &h)
{
	int len = h.size()-1;
	vi nw(len+1);
	for (int a = 0; a <= len; a++)
	{
		for (int b = a+1; b <= len; b++)
		{
			nw[a] = sum(nw[a], mlt(h[b], c[a][b]));
		}
		nw[a] = mlt(nw[a], pow2[a]);
	}
	for (int a = 0; a <= len; a++)
	{
		nw[a] = sum(nw[a], mlt(h[a],pow2[a]-1));
	}

	return nw;
}
vi mrg(vi &v1, vi &v2)
{
	int l1 = v1.size(), l2 = v2.size();
	vi newl1(l1+l2);
	for (int a = 0; a < l1; a++)
	{
		for (int b = 0; b < l2; b++)
		{
			newl1[a + b] = sum(newl1[a + b], mlt(v1[a], v2[b]));
		}
	}
	vi newl(l1 + l2);
	newl[0] = newl1[0];
	for (int i = 1; i < newl.size(); i++)
	{
		newl[i] = sum(newl1[i], newl1[i - 1]);
	}
	return newl;
}
vi seg(vi &h, int l, int r, int hei)
{
//	cerr << l << ' ' << r << ' ' << hei << endl;
	if (r == l)
	{
		vi ans(1);
		ans[0] = 1;
		return ans;
	}
	int cur = -1;
	for (int i = l; i < r; i++)
	{
		if (h[i] == hei)
		{
			cur = i;
			break;
		}
	}
	if (cur == -1)
	{
		vi prev = seg(h, l, r, hei + 1);
		vi tw = layer(prev);
		vvi dyn(r - l + 1, vi(r - l + 1));
		dyn[0][0] = 1;
	//	cerr << l << ' ' << r << ' ' << hei << endl;
		for (int i = l; i < r; i++)
		{
			for (int a = 0; a < dyn[0].size(); a++)
			{
				dyn[i - l + 1][a] = sum(dyn[i - l + 1][a], mlt(dyn[i - l][a], pow2[h[i] - hei-1] - 1));
				if (a > 0)
				{
					dyn[i - l + 1][a] = sum(dyn[i - l + 1][a], mlt(dyn[i - l][a - 1], pow2[h[i] - hei-1]));
				}
			}
		}
		//cerr << "Here" << endl;
		for (int i = 0; i <=r-l; i++)
		{
			tw[i] = sum(tw[i], dyn[r - l][i]);
		}
		return tw;
	}
	else
	{
		vi pr1 = seg(h, l, cur, hei), pr2=seg(h, cur+1, r, hei);
		vi tw = mrg(pr1, pr2);
	//	cerr << l << ' ' << r << ' ' << hei << endl;
		for (int i = 0; i < tw.size(); i++)
		{
			cerr << tw[i] << ' ';
		}
	//	cerr << endl << endl << endl;
		return tw;
	}
}
void prec()
{
	int dva = 1;
	for (int i=0; i < 500; i++)
	{
		pow2[i] = dva;
		dva = sum(dva, dva);
	}
	c[0][0] = 1;
	for (int i = 1; i < 500; i++)
	{
		c[0][i] = 1;
		c[i][i] = 1;
		for (int j = 1; j < i; j++)
		{
			c[j][i] = sum(c[j - 1][i - 1], c[j][i - 1]);
		}
	}
}
void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	prec();
	int n;
	cin >> n;
	vi h(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	vi val = seg(h, 0, n, 0);
	cout << val[0] << endl;
}
int main()
{
	solve();
	int n;
	cin >> n;
}

Measured memory_bytes: 2220