#include<bits/stdc++.h>
 
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
 
//PBDS
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
 
using namespace std;
 
//PBDS_SET
//Index of Value - .order_of_key()
//Value at Index - .find_by_order()
/*
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds_set; 
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> pbds_multiset; 
*/
 
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}
 
///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}
 
int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
 
///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;
 
 int a[N],par[N],cnt[N];
bool vis[N];
 int findroot(int u){
  if(u==par[u])return u;

  return par[u]=findroot(par[u]);
 }

 void merge(int u,int v){
  u=findroot(u);
  v=findroot(v);

  if(u!=v){
    par[u]=v;
    cnt[v]+=cnt[u];
  }
 }

int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){

      int n;
      Int(n);

      for(int i=1;i<=n;++i){
        Int(a[i]);
        par[a[i]]=a[i];
        cnt[a[i]]=1;
      }

      for(int i=1,j=n;i<j;++i,--j){
        if(a[i]!=a[j]){
          merge(a[i],a[j]);
        }
      }
    
      int res=0;
      for(int i=1,j=n;i<j;++i,--j){
        if(a[i]!=a[j]){
          int u=findroot(a[i]);

          if(!vis[u]){
            res+=cnt[u]-1;
            vis[u]=true;
          }
        }
      }
      printf("%d\n", res);



     
        //printf("Case %d: ",++te);
    }
 
    //cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}





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

#define stp(var, init, end) for (auto var = init; var < end; ++var)
#define stpe(var, init, end) for (auto var = init; var <= end; ++var)
#define ll long long

int main(void)
{
    int n;
    ll input;
    cin >> n;
    vector<ll> a(n + 1);
    a[0] = 0;
    stp(i, 1, n + 1)
    {
        cin >> input;
        if (i % 2 == 0)
            a[i] = input;
        else
            a[i] = -input;
    }
    //累積和
    stp(i, 1, n + 1)
    {
        a[i] += a[i - 1];
    }
    sort(a.begin(), a.end());

    //累積和が等しい=和が0
    ll count = 1, ans = 0;
    stp(i, 1, n + 1)
    {
        if (a[i] == a[i - 1])
            ++count;
        else
        {
            if (count > 1)
                ans += count * (count - 1) / 2;
            count = 1;
        }
    }
    if (count > 1)
        ans += count * (count - 1) / 2;

    cout << ans;
    return 0;
}