#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) {
        cin >> a[i];
    }

    ll s[n + 1] = {};
    s[0] = 0;
    rep(i, 1, n + 1) {
        s[i] = s[i - 1] + a[i - 1];
    }

    sort(s, s + n + 1);

    int num[1000000] = {};
    int cnt = 1;
    int j = 0;
    rep(i, 1, n + 1) {
        if (i == n) {
            if (s[i] != s[i - 1]) {
                num[j] = cnt;
                cnt = 1;
                j++;
                num[j] = cnt;
            } else {
                cnt++;
                num[j] = cnt;
            }
        } else {
            if (s[i] != s[i - 1]) {
                num[j] = cnt;
                cnt = 1;
                j++;
            } else cnt++;
        }

    }

    int ans = 0;
    rep(i, 0, 1000000) {
        if (num[i] >= 2) {
            ans += num[i] * (num[i] - 1) / 2;
        }
    }

    cout << ans << endl;
    return 0;

}
