#include <bits/stdc++.h>
inline long long read() {
  long long x = 0;
  char ch = getchar(), w = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * w;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
using namespace std;
const int N = 2e5 + 666;
int n, a[N];
long long pre[N], suf[N];
map<long long, map<long long, long long> > s;
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + a[i];
  for (int i = n; i >= 1; --i) suf[i] = suf[i + 1] + a[i];
  for (int i = 1; i < n; ++i) ++s[pre[i]][suf[i + 1]];
  long long t = 0;
  long long ans = 0;
  for (int i = 1; i < n; ++i) {
    t += a[i];
    --s[t][suf[i + 1]];
    if (s.find(t * 2) != s.end()) ans += s[t * 2][t];
  }
  writeln(ans);
  return 0;
}
