#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int val[200000 + 5];
int value[200000 + 5];
int con[200000 + 5];
long long add[200000 + 5];
void init() {
  add[0] = 0;
  for (int i = 1; i < 200000 + 5; ++i) add[i] = add[i - 1] + i;
}
int main() {
  init();
  int i, j, flag;
  int N;
  long long all;
  scanf("%d", &N);
  memset(val, 0, sizeof(val));
  memset(con, 0, sizeof(con));
  memset(value, 0, sizeof(value));
  all = flag = 0;
  for (i = 1; i <= N; ++i) scanf("%d", &value[i]);
  for (i = 1; i <= N; ++i) {
    if (flag & (1 << (i - 1))) continue;
    val[i - 1] = 0;
    for (j = i; j <= N; ++j) {
      val[j] = val[j - 1] + value[j];
      if (val[j] == 0) ++con[i], flag = flag | (1 << j);
    }
    all += add[con[i]];
  }
  cout << all << endl;
  return 0;
}
