#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 100;
long long n, a[MAXN], m;
bool kek = 0;
vector<pair<long long, long long> > g[MAXN];
void Left(long long pos, long long val) {
  long long sum = 0;
  for (int j = pos - 1; j >= 1; --j) {
    if (a[j] < 0) {
      break;
    }
    sum += a[j];
    if (sum == val * -1) {
      if (!kek) {
        kek = 1;
        m++;
      }
      g[m].push_back(make_pair(j, pos));
    } else if (sum > val * -1) {
      break;
    }
  }
}
void Right(long long pos, long long val) {
  long long sum = 0;
  for (int j = pos + 1; j <= n; ++j) {
    if (a[j] < 0) {
      break;
    }
    sum += a[j];
    if (sum == val * -1) {
      if (!kek) {
        kek = 1;
        m++;
      }
      g[m].push_back(make_pair(pos, j));
    } else if (sum > val * -1) {
      break;
    }
  }
}
void Med(long long pos, long long val) {
  long long sum = 0;
  long long l = pos - 1;
  long long r = pos + 1;
  while (1) {
    if (l <= 0 || r > n) {
      break;
    }
    sum += a[l] + a[r];
    if (sum == val * -1) {
      if (!kek) {
        kek = 1;
        m++;
      }
      g[m].push_back(make_pair(l, r));
    }
    l--;
    r++;
  }
}
int main() {
  cin >> n;
  vector<pair<long long, long long> > ap;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (!a[i]) {
      while (1) {
      }
    }
    if (a[i] < 0) {
      ap.push_back(make_pair(a[i], i));
    }
  }
  for (int i = 0; i < ap.size(); ++i) {
    long long pos = ap[i].second;
    long long val = ap[i].first;
    kek = 0;
    Left(pos, val);
    Right(pos, val);
    Med(pos, val);
  }
  long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    ans += g[i].size();
    for (int j = 0; j < g[i].size(); ++j) {
      long long l = g[i][j].first;
      long long r = g[i][j].second;
      for (int q = 0; q < g[i + 1].size(); ++q) {
        long long l1 = g[i + 1][q].first;
        long long r1 = g[i + 1][q].second;
        if (l1 - r == 1) {
          ans++;
        } else if (l1 - r == 0) {
          ans += (g[i + 1].size() - 1) * (g[i].size() - 1);
        }
      }
    }
  }
  cout << ans;
  return 0;
}
