#include <bits/stdc++.h>
using namespace std;
void InputData(vector<int>*, int);
void FindZeroSumRanges_1(vector<int>*, int);
void FindZeroSumRanges_2(vector<int>*, int);
int main() {
  int N;
  cin >> N;
  vector<int> A;
  InputData(&A, N);
  FindZeroSumRanges_2(&A, N);
  return 0;
}
void InputData(vector<int>* A, int N) {
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    A->push_back(tmp);
  }
}
void FindZeroSumRanges(vector<int>* A, int N) {
  vector<int> critical_gap_pos;
  int count = 0;
  struct LocalFunc {
    static void FindCriticalGapPoints(vector<int>& critical_gap_pos,
                                      vector<int>* A, int N) {
      for (int i = 0; i < N - 1; i++) {
        bool positive_flag = false;
        bool negative_flag = false;
        if (A->at(i) > 0)
          positive_flag = true;
        else if (A->at(i) < 0)
          negative_flag = true;
        if (A->at(i + 1) > 0)
          positive_flag = true;
        else if (A->at(i + 1) < 0)
          negative_flag = true;
        if (positive_flag == true && negative_flag == true) {
          critical_gap_pos.push_back(i);
        }
      }
    }
    static void CountZeroSumRange(vector<int>& critical_gap_pos, vector<int>* A,
                                  int N, int& count) {
      for (int width = 2; width < N; width++) {
        for (int i = 0; i < critical_gap_pos.size(); i++) {
          cout << "width:" << width;
          for (int left_end_num_pos = critical_gap_pos[i] - (width - 2);
               left_end_num_pos <= critical_gap_pos[i]; left_end_num_pos++) {
            cout << "width:" << width << endl;
            int right_end_num_pos = left_end_num_pos + (width - 1);
            if (left_end_num_pos < 0)
              continue;
            else if (right_end_num_pos >= N)
              break;
            else {
              int parts_division = 0;
              for (int itr = 0; itr < width; itr++) {
                parts_division += A->at(left_end_num_pos + itr);
              }
              if (parts_division == 0) {
                count++;
              }
            }
          }
        }
      }
    }
  };
  LocalFunc::FindCriticalGapPoints(critical_gap_pos, A, N);
  for (int i = 0; i < critical_gap_pos.size(); i++) {
    cout << critical_gap_pos[i] << endl;
  }
  LocalFunc::CountZeroSumRange(critical_gap_pos, A, N, count);
  cout << count << endl;
}
void FindZeroSumRanges_2(vector<int>* A, int N) {
  int count = 0;
  for (int width = 2; width < N; width++) {
    for (int left_end_pos = 0; left_end_pos <= (N - 1) - (width - 1);
         left_end_pos++) {
      int parts_division = 0;
      for (int i = 0; i < width; i++) {
        parts_division += A->at(left_end_pos + i);
      }
      if (parts_division == 0) count++;
    }
  }
  cout << count++ << endl;
}
