#include <bits/stdc++.h>
 
                /* Macroses */
#define hxlfiez ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define out     freopen("output.txt", "w", stdout);
#define in      freopen("input.txt", "r", stdin);
#define rall(x) (x).rbegin(), (x).rend()
#define all(x)  (x).begin(), (x).end()
#define rs(x)   ((x) << 1 | 1)
#define ls(x)   ((x) << 1)
#define int     long long
#define pb      push_back    
#define ppb     pop_back
#define sz(x)   (x).size()   
#define S       second
#define F       first
 
using namespace std;
            
const int mod = 1e9 + 7, N = 1e5;
int a[N];
signed main()
{
    hxlfiez 
	int n, ans = 0;
	cin >> n;
    for(int i = 1; i <= n; i++){
     	cin >> a[i];
    }
	
	for(int i = 1; i < n; i++){
     	vector<int> v;
    	for(int j = i; j <= n; j++){
    		
      		v.pb(a[j]);
      		sort(all(v));
      	
      		if(v[sz(v) - 1] + v[0] == v[sz(v) - 2] + v[1]){
       			ans++;
      		}	
     	}
    }
	cout << ans;
}
