#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long long ll;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
typedef pair<ll,int> P;
#define rep(i,l,r) for (int i(l),_##i(r);i<=_##i;i++)
#define per(i,l,r) for (int i(r),_##i(l);i>=_##i;i--)
#define all(x) (x).begin(),(x).end()
#define forall(x,y) for (const int &y: e[x])

int n,a[300010];
P b[300010];

void solve(){
	n=read();
	rep(i,1,n) a[i]=read()*(i&1?-1:1);
	ll S=0; b[0]=P(0,0);
	rep(i,1,n) S+=a[i],b[i]=P(S,i);
	sort(b,b+n+1);
	ll z=0; S=0;
	rep(i,1,n){
		S+=a[i];
		auto l=lower_bound(b,b+n+1,P(S,0));
		auto r=lower_bound(b,b+n+1,P(S,i));
//		printf("test %lld,%d: ",S,i);
//		rep(j,l-b,r-b-1) printf("%lld,%d  ",b[j].fi,b[j].se);
//		puts("");
		z+=r-l;
	}
	printf("%lld\n",z);
}

int main()
{
	for (int T=1;T--;) solve();
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	int ans = 0;
	
	for(int i = 0; i<(1<<((h-1)*w)); i++){
		for(int j = 0; j<(1<<((w-1)*h)); j++){
			if(__builtin_popcount(i)+__builtin_popcount(j)!=a)continue;
			vector<vector<int>>arr(h+1,vector<int>(w+1));
			int cur = 1;
			for(int a = 0; a<h-1; a++){
				for(int b = 0; b<w; b++){
					if((1<<(a*w+b))&i){
						arr[a][b] = cur; arr[a+1][b] = cur;
						cur++;
					}
				}
			}
			for(int b = 0; b<w-1; b++){
				for(int a = 0; a<h; a++){
					if((1<<(b*h+a))&j){
						arr[a][b] = cur; arr[a][b+1] = cur;
						cur++;
					}
				}
			}
			bool f = true;
			for(int a = 0; a<h-1; a++){
				for(int b = 0; b<w; b++){
					if((1<<(a*w+b))&i){
						if(arr[a][b]==arr[a+1][b]&&arr[a][b]>0){
							continue;
						}
						f = false;
					}
					else{
						if(arr[a][b]==0||arr[a+1][b]==0||arr[a][b]!=arr[a+1][b]){
							continue;
						}
						f = false;
					}
				}
			}
			for(int b = 0; b<w-1; b++){
				for(int a = 0; a<h; a++){
					if((1<<(b*h+a))&j){
						if(arr[a][b]==arr[a][b+1]&&arr[a][b]>0){
							continue;
						}
						f= false;
					}
					else{
						if(arr[a][b]==0||arr[a][b+1]==0||arr[a][b]!=arr[a][b+1]){
							continue;
						}
						f = false;
					}
				}
			}
			ans+=f;
		}
	}
	cout << ans << "\n";
	return 0;
}