#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int P = 998244353;
int upd(int x){return x + (x >> 31 & P);}
int dp[403][403][2] , pw[2][403][403] , N , h[403] , cnt;

int DP(int l , int r){
	if(l > r) return 0;
	int id = ++cnt , val = 1e9 , num = 0;
	for(int j = l ; j <= r ; ++j) val = min(val , h[j]);
	int pre = l - 1 , sz = 0; dp[id][0][0] = 1;
	for(int j = l ; j <= r + 1 ; ++j)
		if(j == r + 1 || val == h[j]){
			++num; int t = DP(pre + 1 , j - 1);
			if(t){
				static int tmp[403][2]; memset(tmp , 0 , sizeof(tmp));
				for(int p = 0 ; p <= sz ; ++p)
					for(int q = 0 ; q < j - pre ; ++q)
						for(int x = 0 ; x < 2 ; ++x)
							for(int y = 0 ; y < 2 ; ++y)
								tmp[p + q][x | y] = (tmp[p + q][x | y] + 1ll * dp[id][p][x] * dp[t][q][y]) % P;
				memcpy(dp[id] , tmp , sizeof(dp[id])); sz += j - pre - 1;
			}
			pre = j;
		}
	--num;
	for(int i = 1 ; i <= num ; ++i){
		static int tmp[403][2]; memcpy(tmp , dp[id] , sizeof(tmp));
		for(int j = 0 ; j <= r - l + 1 ; ++j){
			tmp[j + 1][0] = upd(tmp[j + 1][0] - dp[id][j][0]);
			tmp[j + 1][1] = upd(tmp[j + 1][1] + dp[id][j][0] - P);
		}
		memcpy(dp[id] , tmp , sizeof(dp[id]));
	}
	int len = val - max(h[l - 1] , h[r + 1]);
	for(int i = 0 ; i <= r - l + 1 ; ++i){
		dp[id][i][0] = 1ll * dp[id][i][0] * pw[0][r - l + 1 - i][len] % P;
		dp[id][i][1] = 1ll * dp[id][i][1] * pw[1][r - l + 1 - i][len] % P;
	}
	return id;
}

int main(){
	scanf("%d" , &N); for(int i = 1 ; i <= N ; ++i) scanf("%d" , h + i);
	for(int i = 0 ; i <= N ; ++i) pw[0][i][0] = pw[0][0][i] = 1;
	for(int j = 1 ; j <= N ; ++j){
		pw[0][j][1] = upd(pw[0][j - 1][1] + pw[0][j - 1][1] - P); pw[1][j][1] = pw[0][j][1] - 1;
		for(int k = 2 ; k <= N ; ++k){
			pw[0][j][k] = 1ll * pw[0][j][k - 1] * pw[0][j][1] % P;
			pw[1][j][k] = 1ll * pw[1][j][k - 1] * pw[1][j][1] % P;
		}
	}
	int t = DP(1 , N); int sum = 0;
	for(int i = 0 ; i <= N ; ++i) for(int j = 0 ; j <= 1 ; ++j) sum = upd(sum + dp[t][i][j] - P);
	printf("%d\n" , sum); return 0;
}
