Description
Input
Output
Sample Input
4 1701 1702 1703 1704
Sample Output
8
HINT
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
const int nmax=1010;
int a[nmax],f[nmax][nmax][2];
#define rep(i,n) for(int i=1;i<=n;i++)
int main()
{
int n,i;
cin>>n;
rep(i,n) cin>>a[i];
rep(i,n) f[i][i][0]=1;
for(i=n-1;i>=1;i--)
for(int j=i+1;j<=n;j++){
f[i][j][0]=f[i+1][j][0]*(a[i]<a[i+1])+f[i+1][j][1]*(a[i]<a[j]);
f[i][j][1]=f[i][j-1][1]*(a[j]>a[j-1])+f[i][j-1][0]*(a[j]>a[i]);
f[i][j][0]%=19650827;
f[i][j][1]%=19650827;
}
cout<<(f[1][n][0]+f[1][n][1])%19650827<<endl;
return 0;
}