#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
#define all(x) (x).begin(),(x).end()
int f[51][51][51][51],w[51];
void upd(int &x,int y) { x=(x+y)%mod; }
void solve(int n)
{
vector<int> a(n+1);
for (int i=1; i<=n; ++i) cin>>a[i];
memset(f,0,sizeof f);
for (int len=1; len<=n; ++len)
{
for (int l=1; l<=n; ++l)
{
int r=l+len-1;
for (int i=l; i<=r; ++i)
{
memset(w,0,sizeof w);
for (int k=i+1; k<=r; ++k)
{
if (a[k]>a[i]) continue;
for (int j=1; j<=a[k]; ++j)
{
upd(w[j],f[i+1][r][k][j]);
}
}
for (int j=1; j<=n; ++j) ++w[j];
for (int j=1; j<=a[l]; ++j)
{
for (int k=l; k<i; ++k)
{
if (a[k]<j) continue;
if (a[k]>a[i]) continue;
upd(f[l][r][i][j],f[l][i-1][k][j]*w[a[k]+1]);
}
}
}
}
}
int ans=0;
for (int i=1; i<=n; ++i)
{
for (int j=1; j<=a[i]; ++j)
{
upd(ans,f[1][n][i][j]);
}
}
cout<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int n;
while (cin>>n)
{
solve(n);
}
}