#include <bits/stdc++.h>
using namespace std;
void run() {
  int n;
  scanf("%d", &n);
  vector<int> x(n);
  for (int i = (0); i < (n); ++i) scanf("%d", &x[i]);
  long long sum = 0;
  for (int i = (0); i < (n); ++i) sum += x[i];
  if (sum % 3 != 0) {
    printf("0\n");
    return;
  }
  long long part = sum / 3;
  long long two = 0, ret = 0, parsum = 0;
  for (int i = (0); i < (n - 1); ++i) {
    parsum += x[i];
    if (parsum == 2 * part) ret += two;
    if (parsum == part) two++;
  }
  cout << ret << endl;
}
int main() {
  run();
  return 0;
}
