#include <bits/stdc++.h>
using namespace std;
uint xor128() {
  static uint x = 123456789, y = 362436069, z = 521288629, w = 88675123;
  uint t = (x ^ x << 11);
  x = y;
  y = z;
  z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
struct node {
  node *l, *r;
  long long val;
  int cnt, siz;
};
node pool[400000];
int pointer = 0;
inline int siz(node* t) { return t ? t->siz : 0; }
inline node* update(node* t) {
  if (!t) return t;
  t->siz = siz(t->l) + siz(t->r) + 1;
  return t;
}
node* merge(node* l, node* r) {
  if (!l) return r;
  if (!r) return l;
  if (xor128() % (siz(l) + siz(r)) < (uint)siz(l)) {
    l->r = merge(l->r, r);
    return update(l);
  } else {
    r->l = merge(l, r->l);
    return update(r);
  }
}
pair<node*, node*> split(node* t, int k) {
  if (!t) return make_pair((node*)NULL, (node*)NULL);
  if (t->val < k) {
    auto p = split(t->r, k);
    t->r = p.first;
    return make_pair(update(t), update(p.second));
  } else {
    auto p = split(t->l, k);
    t->l = p.second;
    return make_pair(update(p.first), update(t));
  }
}
node* left(node* t) {
  if (!t) return t;
  if (!t->l) return t;
  return left(t->l);
}
int main() {
  int n;
  scanf("%d", &n);
  node* root = &pool[pointer++];
  root->val = 0;
  root->cnt = 1;
  root->siz = 1;
  long long ans = 0, cnt = 0;
  for (int i = 0; i < (n); i++) {
    int a;
    scanf("%d", &a);
    cnt += a;
    auto p = split(root, cnt);
    node* t = left(p.second);
    if (t && t->val == cnt) {
      ans += t->cnt;
      t->cnt++;
      root = merge(p.first, p.second);
    } else {
      t = &pool[pointer++];
      t->val = cnt;
      t->cnt = 1;
      t->siz = 1;
      root = merge(merge(p.first, t), p.second);
    }
  }
  cout << ans << endl;
}
