#include<iostream>
using namespace std;
const long long int maxn=10009;
int n;
short a[maxn];
short dp[maxn][maxn];
bool has1[maxn][maxn];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]=1-(a[i]%2);
    }
    for(int i=0;i<n;i++){
        dp[i][i]=a[i];
        has1[i][i]=a[i];
    }
    for(int diff=1;diff<n;diff++){
        for(int i=0;i+diff<n;i++){
            int j=i+diff;
            has1[i][j]=has1[i][j-1]||has1[i+1][j];
            dp[i][j]=dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]+has1[i][j];
        }
    }
    cout<<dp[0][n-1]<<"\n";
    return 0;
}
