#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// head

const int N = 3e5 + 5;
int a[N], n;

int main(void){
	scanf("%d", &n);
	ll sum1 = 0, sum2 = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum1 += a[i];
		sum2 += a[i] * a[i];
	}
	ll ans = (n - 1) * sum2 - (sum1 * sum1 - sum2);
	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  
  map<long long,long long> height;
  long long num =0;
  height[0]++;
  unsigned long long count =0;
  
  for(int i=0;i<n;i++){
    if(i%2==0) {
      num += a[i];
      height[num] ++;
    }else{
      num -= a[i];
      height[num] ++;
    }
  }

  for (auto i:height){
    //cout<< i.first <<' '<< i.second <<endl;
    count += i.second*(i.second-1)/2;
  }

  cout << count << endl;
  
  

}

