#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int mo=998244353;
const int N=405;
int n,a[N],C[N][N],P[N];
int lson[N*2],rson[N*2];
int val[N*2],len[N*2],nd;
int f[N*2][N],g[N*2][N];
int tf[N],tg[N];
void init(){
	For(i,0,N-1) C[i][0]=1;
	For(i,1,N-1) For(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
	For(i,(P[0]=1),N-1) P[i]=2ll*P[i-1]%mo;
}
int build_tr(int l,int r){
	if (l>r) return 0;
	int p=l,k=++nd;
	For(i,l,r) if (a[i]<a[p]) p=i;
	val[k]=a[p]; len[k]=r-l+1;
	lson[k]=build_tr(l,p-1);
	rson[k]=build_tr(p+1,r);
	return k;
}
void get_ans(int x,int lad){
	if (!x) return;
	int sz=len[x];
	int ls=lson[x],n=len[ls];
	int rs=rson[x],m=len[rs];
	get_ans(ls,val[x]);
	get_ans(rs,val[x]);
	For(i,0,n) For(j,0,m){
		f[x][i+j]=(f[x][i+j]+1ll*f[ls][i]*f[rs][j])%mo;
		f[x][i+j+1]=(f[x][i+j+1]+1ll*f[ls][i]*f[rs][j])%mo;
		g[x][i+j+1]=(g[x][i+j+1]+1ll*g[ls][i]*g[rs][j])%mo;
	}
	For(T,1,val[x]-lad){
		memset(tf,0,sizeof(tf));
		memset(tg,0,sizeof(tg));
		For(j,0,sz){
			tf[j]=(tf[j]+g[x][j])%mo;
			tg[j]=(tg[j]+g[x][j])%mo;
			For(k,0,sz-j){
				int dif=1ll*P[j]*C[j+k][k]%mo;
				if (!k) dif=(dif+mo-1)%mo;
				tf[j]=(tf[j]+1ll*dif*f[x][j+k])%mo;
				tg[j]=(tg[j]+1ll*dif*g[x][j+k])%mo; 
			}
		}
		memcpy(f[x],tf,sizeof(tf));
		memcpy(g[x],tg,sizeof(tg));
	}
}
int main(){
	init();
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	int rt=build_tr(1,n);
	f[0][0]=g[0][0]=1; 
	get_ans(rt,0);
	printf("%d\n",f[rt][0]);
}

### Prompt

Develop a solution in CPP to the problem described below:

Let us consider a grid of squares with N rows and N columns. Arbok has cut out some part of the grid so that, for each i = 1, 2, \ldots, N, the bottommost h_i squares are remaining in the i-th column from the left. Now, he wants to place rooks into some of the remaining squares.

A rook is a chess piece that occupies one square and can move horizontally or vertically, through any number of unoccupied squares. A rook can not move through squares that have been cut out by Arbok.

Let's say that a square is covered if it either contains a rook, or a rook can be moved to this square in one move.

Find the number of ways to place rooks into some of the remaining squares so that every remaining square is covered, modulo 998244353.

Constraints

* 1 \leq N \leq 400
* 1 \leq h_i \leq N
* All input values are integers.

Input

Input is given from Standard Input in the following format:


N
h_1 h_2 ... h_N


Output

Print the number of ways to place rooks into some of the remaining squares so that every remaining square is covered, modulo 998244353.

Examples

Input

2
2 2


Output

11


Input

3
2 1 2


Output

17


Input

4
1 2 4 1


Output

201


Input

10
4 7 4 8 4 6 8 2 3 6


Output

263244071

### Response

```cpp
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int mo=998244353;
const int N=405;
int n,a[N],C[N][N],P[N];
int lson[N*2],rson[N*2];
int val[N*2],len[N*2],nd;
int f[N*2][N],g[N*2][N];
int tf[N],tg[N];
void init(){
	For(i,0,N-1) C[i][0]=1;
	For(i,1,N-1) For(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
	For(i,(P[0]=1),N-1) P[i]=2ll*P[i-1]%mo;
}
int build_tr(int l,int r){
	if (l>r) return 0;
	int p=l,k=++nd;
	For(i,l,r) if (a[i]<a[p]) p=i;
	val[k]=a[p]; len[k]=r-l+1;
	lson[k]=build_tr(l,p-1);
	rson[k]=build_tr(p+1,r);
	return k;
}
void get_ans(int x,int lad){
	if (!x) return;
	int sz=len[x];
	int ls=lson[x],n=len[ls];
	int rs=rson[x],m=len[rs];
	get_ans(ls,val[x]);
	get_ans(rs,val[x]);
	For(i,0,n) For(j,0,m){
		f[x][i+j]=(f[x][i+j]+1ll*f[ls][i]*f[rs][j])%mo;
		f[x][i+j+1]=(f[x][i+j+1]+1ll*f[ls][i]*f[rs][j])%mo;
		g[x][i+j+1]=(g[x][i+j+1]+1ll*g[ls][i]*g[rs][j])%mo;
	}
	For(T,1,val[x]-lad){
		memset(tf,0,sizeof(tf));
		memset(tg,0,sizeof(tg));
		For(j,0,sz){
			tf[j]=(tf[j]+g[x][j])%mo;
			tg[j]=(tg[j]+g[x][j])%mo;
			For(k,0,sz-j){
				int dif=1ll*P[j]*C[j+k][k]%mo;
				if (!k) dif=(dif+mo-1)%mo;
				tf[j]=(tf[j]+1ll*dif*f[x][j+k])%mo;
				tg[j]=(tg[j]+1ll*dif*g[x][j+k])%mo; 
			}
		}
		memcpy(f[x],tf,sizeof(tf));
		memcpy(g[x],tg,sizeof(tg));
	}
}
int main(){
	init();
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	int rt=build_tr(1,n);
	f[0][0]=g[0][0]=1; 
	get_ans(rt,0);
	printf("%d\n",f[rt][0]);
}

```