#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef vector<ll> vl;
typedef pair<vl,vl> t;

const ll mod = 998244353;

int n,a[405];
ll bin[400*400+5],C[405][405];

ll modpow(ll a,ll n){
    ll ret = 1;
    while(n){
        if(n&1) ret = ret*a%mod;
        a = a*a%mod;
        n >>= 1;
    }
    return ret;
}

t rec(int l,int r,int dep){
	int mn = mod;
	for(int i=l;i<=r;i++) mn = min(mn,a[i]);
	int cnt = 0;
	ll dp[2][2][405] = {};
	int cur = 0, nxt = 1;
	int sum = 0;
	dp[cur][0][0] = 1;
	
	for(int i=l;i<=r;i++){
		if(a[i] == mn){
			if(cnt){
				t ret = rec(i-cnt,i-1,mn);
				rep(x,2) rep(y,405) dp[nxt][x][y] = 0;
				rep(x,2) rep(y,405) dp[cur][x][y] %= mod;
				rep(x,2) rep(y,405){
					if(dp[cur][x][y] == 0) continue;
					rep(z,ret.fi.size()){
						dp[nxt][x][y+z] += dp[cur][x][y] * ret.fi[z] % mod;
					}
					rep(z,ret.sc.size()){
						dp[nxt][1][y+z] += dp[cur][x][y] * ret.sc[z] % mod;
					}
				}
				swap(cur,nxt);
			}
			cnt = 0;
			sum++;
		}
		else cnt++;
	}
	if(cnt){
		t ret = rec(r-cnt+1,r,mn);
		rep(x,2) rep(y,405) dp[nxt][x][y] = 0;
		rep(x,2) rep(y,405) dp[cur][x][y] %= mod;
		rep(x,2) rep(y,405){
			if(dp[cur][x][y] == 0) continue;
			rep(z,ret.fi.size()){
				dp[nxt][x][y+z] += dp[cur][x][y] * ret.fi[z] % mod;
			}
			rep(z,ret.sc.size()){
				dp[nxt][1][y+z] += dp[cur][x][y] * ret.sc[z] % mod;
			}
		}
		swap(cur,nxt);
	}
	rep(x,2) rep(y,405) dp[nxt][x][y] = 0;
	rep(x,2) rep(y,405) dp[cur][x][y] %= mod;

	rep(x,2) rep(y,405){
		if(dp[cur][x][y] == 0) continue;
		rep(z,sum+1){
			dp[nxt][0][y+z] += dp[cur][x][y] * (bin[(mn-dep) * (r-l+1-y-z)]-modpow(bin[(r-l+1-y-z)]-1,mn-dep)) % mod * C[sum][z] % mod;
			
			if(x == 1) dp[nxt][1][y+z] += dp[cur][x][y] * modpow(bin[(r-l+1-y-z)]-1,mn-dep) % mod * C[sum][z] % mod;
			else if(z) dp[nxt][1][y+z] += dp[cur][x][y] * modpow(bin[(r-l+1-y-z)]-1,mn-dep) % mod * C[sum][z] % mod;
			else if(y) dp[nxt][0][y+z] += dp[cur][x][y] * modpow(bin[(r-l+1-y-z)]-1,mn-dep) % mod * C[sum][z] % mod;
			else dp[nxt][0][y+z] += dp[cur][x][y] * modpow(bin[(r-l+1-y-z)]-1,mn-dep) % mod * C[sum][z] % mod;
		}
	}
	swap(cur,nxt);
	//rep(i,5) cout << dp[cur][0][i] << " " << dp[cur][1][i] << endl;
	vl z,o;
	rep(i,405) z.pb( (dp[cur][0][i]%mod+mod) % mod );
	rep(i,405) o.pb( (dp[cur][1][i]%mod+mod) % mod );
	
	while(z.back() == 0) z.pop_back();
	while(o.back() == 0) o.pop_back();
	/*cout << z.size() << endl;
	rep(i,z.size()) cout << z[i] << " "; cout << endl;
	
	cout << o.size() << endl;
	rep(i,o.size()) cout << o[i] << " "; cout << endl;*/
	return mp(z,o);
}

int main(){
    bin[0] = 1;
    for(int i=1;i<400*400+5;i++) bin[i] = bin[i-1] * 2LL % mod;
    rep(i,405) rep(j,i+1){
        if(j == 0 || j == i) C[i][j] = 1;
        else C[i][j] = (C[i-1][j]+C[i-1][j-1])%mod;
    }
	cin >> n;
	repn(i,n) cin >> a[i];
	
	t ret = rec(1,n,0);
	ll ans = 0;
	rep(i,(ret.fi).size()){
		if(i%2 == 0) ans += ret.fi[i];
		else ans -= ret.fi[i];
	}
	cout << (ans%mod+mod)%mod << endl;
}

Measured memory_bytes: 7936