#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  long long int ret = 0;
  vector<long long int> calcLis = {};
  vector<long long int> cntLis = {};
  int nextDplCnt = 0;
  for (int i = 0; i < N; i++) {
    long long int a;
    cin >> a;
    calcLis.push_back(0);
    cntLis.push_back(1 + nextDplCnt);
    nextDplCnt = 0;
    int j = 0;
    while (j < calcLis.size()) {
      calcLis[j] += a;
      if (calcLis[j] == 0) {
        ret += cntLis[j];
        nextDplCnt += cntLis[j];
        calcLis.erase(calcLis.begin() + j);
        cntLis.erase(cntLis.begin() + j);
      } else {
        j++;
      }
    }
  }
  cout << ret;
  return 0;
}
