#include<bits/stdc++.h> 
//#include<atcoder/all>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
//using namespace atcoder;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i, n) cin >> a[i + 1];
    map<ll, int> m;
    rep(i, n) a[i + 1] += a[i];
    rep(i, n + 1)
        m[a[i]]++;
    ll ans = 0;
    rep(i, m.size()){
        auto itr = m.begin() + i;
        ans += *itr * (*itr - 1) / 2;
    }
    cout << ans << endl;
}