#include <bits/stdc++.h>
using namespace std;
const int fx[] = {+1, -1, +0, +0}, fy[] = {+0, +0, +1, -1};
const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6;
int Case = 1, cas = 0;
long long n, A[mx], Sum;
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    Sum += A[i];
  }
  if (Sum % 3)
    cout << 0 << endl;
  else {
    long long Ans = 0, taken = 0, milse = 0;
    long long target = Sum / 3;
    for (int i = 1; i < n; i++) {
      taken += A[i];
      if (taken == target + target) Ans += milse;
      if (taken == target) milse++;
    }
    cout << Ans << endl;
  }
  return 0;
}
