#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a[N];
map<long long, int> st;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  long long s = 0, ans = 0;
  st[0] = 0;
  int v = 0;
  for (int i = 1; i <= n; i++) {
    s += a[i];
    if (st.count(s)) v = max(v, st[s] + 1);
    if (s == 0) v = max(v, 1);
    if (a[i]) ans += i - v;
    st[s] = i;
  }
  printf("%lld\n", ans);
  return 0;
}
