#include <bits/stdc++.h>
using namespace std;
const int max_n = 5e5 + 5;
long long sum[max_n];
map<long long, int> M;
int main() {
  int n;
  scanf("%d", &n);
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    int a_i;
    scanf("%d", &a_i);
    sum[i] = sum[i - 1] + a_i;
  }
  M[sum[n - 1]]++;
  long long ans = 0;
  for (int i = n - 2; i >= 1; i--) {
    if (sum[n] - sum[i] == 2 * sum[i]) {
      ans += M[2 * sum[i]];
    }
    M[sum[i]]++;
  }
  printf("%lld\n", ans);
  return 0;
}
