#include <bits/stdc++.h>
using namespace std;
int main() {
  int ncases;
  cin >> ncases;
  vector<int> numbs(ncases, 0);
  unordered_map<long long, int> sufixes;
  long long sum = 0;
  for (int z = 0; z < ncases; z++) {
    int tmp;
    cin >> tmp;
    numbs[z] = tmp;
    sum += tmp;
  }
  long long sums = sum;
  for (int z = 0; z < ncases - 1; z++) {
    sums -= numbs[z];
    sufixes[sums]++;
  }
  if (sum % 3) {
    cout << 0 << endl;
    return 0;
  }
  sums = sum - numbs[0];
  long long ret = 0;
  long long prefsum = numbs[0];
  for (int z = 1; z < ncases - 1; z++) {
    sufixes[sums]--;
    sums -= numbs[z];
    if (prefsum == sum / 3) {
      ret += sufixes[sum / 3];
    }
    prefsum += numbs[z];
  }
  cout << ret << endl;
}
