https://blog.csdn.net/dofypxy/article/details/79145068
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=l; i<=r; i++)
using namespace std; const int N=,mod=;
int n,ans,r[N],mx,f[N][N][N],sl[N][N][N],sr[N][N][N]; int main(){
freopen("P4063.in","r",stdin);
freopen("P4063.out","w",stdout);
scanf("%d",&n);
rep(i,,n) scanf("%d",&r[i]),mx=max(mx,r[i]+);
rep(i,,mx) sl[][i][mx]=sr[][][i]=;
rep(i,,n){
memset(f,,sizeof(f));
rep(a,,r[i]){
rep(L,,a-) rep(R,a+,mx) f[a][L][R]=(sl[L][L][R]+sr[R][L][R])%mod;
rep(R,a,mx) f[a][a][a]=(f[a][a][a]+sl[a][mx][R])%mod;
rep(a1,,mx) if (a1!=a) f[a][a][a]=(f[a][a][a]+sl[a1][a1][a]+sr[a1][a][a1])%mod;
}
memset(sl,,sizeof(sl)); memset(sr,,sizeof(sr));
rep(a,,r[i]) rep(L,,mx) rep(R,a,mx) sl[a][L][R]=(f[a][L][R]+(L ? sl[a][L-][R] : ))%mod;
rep(a,,r[i]) rep(L,,a) for (int R=mx; ~R; R--) sr[a][L][R]=(f[a][L][R]+sr[a][L][R+])%mod;
}
rep(a,,r[n]) rep(L,,a) rep(R,a,mx) ans=(ans+f[a][L][R])%mod;
printf("%d\n",ans);
return ;
}