#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e6 + 7;
int n, a[N];
void Init() {
  for (int i = (0); i < (n); ++i) scanf("%d", a + i);
}
int Solve() {
  long long sum = 0;
  for (int i = (0); i < (n); ++i) sum += a[i];
  if (sum % 3 != 0) return puts("0");
  sum /= 3;
  long long l = 0, r = 0, tmp = 0;
  for (int i = (0); i < (n - 1); ++i) {
    tmp += a[i];
    if (tmp == sum * 2) r += l;
    if (tmp == sum) l++;
  }
  return printf("%lld\n", r);
}
int main() {
  while (~scanf("%d", &n)) {
    Init();
    Solve();
  }
  return 0;
}
