/*
区间DP,其中一种类型,
转移分阶段性,且阶段性分两组
i组,j组
*/
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int A = 1e7+10;
const int B = 1e6+10;
const int mod = 19650827;
const int inf = 0x3f3f3f3f;
inline int read() {
char c = getchar();
int x = 0, f = 1;
for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return x * f;
}
int f[2000][2000],g[2000][2000],n,a[B];
int main()
{
int x;
n=read();
for (int i=1;i<=n;i++)
{
a[i]=read();
f[i][i]=1;
//g[i][i]=1;
}
for (int len=2;len<=n;len++)
for (int i=1;i+len-1<=n;i++)
{
int j=i+len-1;
f[i][j]=(f[i+1][j]*(a[i+1]>a[i])+g[i+1][j]*(a[i]<a[j]))%mod;
g[i][j]=(f[i][j-1]*(a[j]>a[i])+g[i][j-1]*(a[j]>a[j-1]))%mod;
}
int ans=(f[1][n]+g[1][n])%mod;
printf("%d",ans);
}