#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <int> vi;
typedef vector <string> vs;
typedef vector <vector <llong> > matrix;

typedef pair <llong, llong> pll;

typedef map <int, int> mii;

typedef set <llong> sl;

const int MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const int INF = 1e9;
const llong LINF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;}

int n;
llong a[MXN], pref[MXN];

map <llong, int> cnt, used;

int main () {
    android;
   // freopen ("input.txt", "r", stdin);
    //freopen ("output1.txt", "w", stdout);
    cin >> n;
    cnt[0] = 1;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
        cnt[pref[i]] ++;
    }
    llong ans = 0;
    for (int i = 1; i <= n; i ++) {
        ans += (cnt[pref[i]] - 1) * cnt[pref[i]] / 2 * (1 - used[pref[i]]);
        used[pref[i]] = 1;
    }
    cout << ans;
    return 0;
}
