#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int val[200000 + 5];
int value[200000 + 5];
int con[200000 + 5];
int do_add(const int& a) {
  int add = 0;
  for (int i = 1; i <= a; ++i) {
    add += i;
  }
  return add;
}
int main() {
  int i, j, flag;
  int N, all;
  while (scanf("%d", &N) != EOF) {
    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 += do_add(con[i]);
    }
    printf("%d\n", all);
  }
  return 0;
}
