DP.
AC code:
#include <cstdio>
const int N=1010;
const int TOMOD=19650827;
int n,ans;
int a[N];
int f[N][N],g[N][N];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) f[i][1]=g[i][1]=1;
for(int j=2;j<=n;j++){
for(int i=1;i<=n;i++){
if(i+1<=n&&a[i]<a[i+1])
f[i][j]=(f[i][j]+f[i+1][j-1])%TOMOD;
if(i+j-1<=n&&i+1!=i+j-1&&a[i]<a[i+j-1])
f[i][j]=(f[i][j]+g[i+j-1][j-1])%TOMOD;
if(i-1>=1&&a[i]>a[i-1])
g[i][j]=(g[i][j]+g[i-1][j-1])%TOMOD;
if(i-j+1>=1&&i-j+1!=i-1&&a[i]>a[i-j+1])
g[i][j]=(g[i][j]+f[i-j+1][j-1])%TOMOD;
}
}
ans=(f[1][n]+g[n][n])%TOMOD;
printf("%d\n",ans);
return 0;
}