#include <bits/stdc++.h>
using namespace std;
long long dp[1002][1003][2]={0};//from i to j the last one was left 0 or right 1
int n,h[1004]={0};
int main(int argc, char** argv) {
freopen("chorusu.in","r",stdin);
freopen("chorusu.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
cin>>h[i];
}
for(int i=1;i<=n;i++){
//dp[i][i][0]=1;
dp[i][i][1]=1;
}
for(int s=1;s<=n;s++){
for(int l=1;l<=n;l++){
int r=l+s;
if(r>n)break;
//left
if(h[l]<h[r]){//
dp[l][r][0]+=dp[l+1][r][1];
}
if(h[l]<h[l+1]){
dp[l][r][0]+=dp[l+1][r][0];
}
//right
if(h[r-1]<h[r]){
dp[l][r][1]+=dp[l][r-1][1];
}
if(h[l]<h[r]){
dp[l][r][1]+=dp[l][r-1][0];
}
dp[l][r][0]%=19650827;
dp[l][r][1]%=19650827;
}
}
cout<<(dp[1][n][0]+dp[1][n][1])%19650827;;
return 0;
}