//
//  main.cpp
//  test
//
//  Created by wyzwyz on 2021/5/13.
//

#include<cstdio>
#include<cctype>
#include<map>

#define maxn 505505

template<class T>

inline T read(){
    T r=0,f=0;
    char c;
    while(!isdigit(c=getchar()))f|=(c=='-');
    while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
    return f?-r:r;
}

template<class T>

inline T min(T a,T b){
    return a<b?a:b;
}

int n,a[maxn];

long long sum[2][maxn];

std::map<long long,int> cnt;

int main(){
    n=read<int>();
    for(int i=1;i<=n;i++)
        a[i]=read<int>();
    sum[1][1]=a[1];
    cnt[-a[1]]=1;
    for(int i=2;i<=n;i++){
        if(i&1){
            sum[0][i]=sum[0][i-1];
            sum[1][i]=sum[1][i-2]+a[i];
        }
        else {
            sum[1][i]=sum[1][i-1];
            sum[0][i]=sum[0][i-2]+a[i];
        }
        cnt[sum[0][i]-sum[1][i]]++;
    }
    long long ans=cnt[0];
    for(int i=1;i<n;i++){
        cnt[sum[0][i]-sum[1][i]]--;
        ans+=cnt[sum[0][i]-sum[1][i]];
    }
    printf("%lld\n",ans);
    return 0;
}
#include<bits/stdc++.h>
using namespace std;

#define ll  long long
#define ull unsigned  long long
#define pll  pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
const ll maxn =7e5+100;
const ll mod=1e9+7 ;
const ll base=2e18;
ll n;
vector<pll> adj[maxn];
ll dp[(1ll<<18)];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.ans","w",stdout);
    }
    ll  m;
     cin>> n>> m ;
     dp[0]=1;
     while (m--)
     {
         ll x, y, z;
          cin>>x>> y>> z;
          adj[x].pb(make_pair(y-1,z));
     }
     for (int i=1;i<(1ll<<n);i++)
     {
         vector<ll> vt;
         for (int j=0;j<n;j++)
         {
             if (i&(1ll<<j))
             {
                 dp[i]+=dp[i^(1ll<<j)];
                 vt.pb(j);
             }
         }
         ll x=__builtin_popcount(i);
         for (auto p:adj[x])
         {
             ll y=p.ff;
             ll z=p.ss;
             auto h=upper_bound(vt.begin(),vt.end(),y)-vt.begin();
             if (h>z) dp[i]=0;
         }
     }
     cout <<dp[(1ll<<n)-1];

}


