#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> v(n);
  for (long long &i : v) cin >> i;
  if (n < 3) {
    cout << 0 << endl;
    exit(0);
  }
  vector<long long> l(n), r(n);
  r[n - 1] = v[n - 1];
  for (int i = n - 2; i >= 0; i--) r[i] = r[i + 1] + v[i];
  l[0] = v[0];
  for (int i = 1; i < n; i++) l[i] = l[i - 1] + v[i];
  map<long long, long long> m;
  for (int i = 1; i <= n - 2; i++)
    if (2 * r[i + 1] == l[i]) m[r[i + 1]]++;
  long long ans = 0;
  for (int i = 0; i < n - 2; i++) {
    if (i >= 1 && 2 * r[i + 1] == l[i]) m[r[i + 1]]--;
    ans += m[l[i]];
  }
  cout << ans << endl;
  exit(0);
}
