#include <bits/stdc++.h>
using namespace std;
int mem[10][10];
long long n;
int ways = 0;
vector<int> vec;
int x;
string line;
int main() {
  cin >> n;
  bool zeroe = true;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (i == 0) {
      vec.push_back(x);
    } else {
      vec.push_back(x + vec[i - 1]);
    }
    if (x != 0) zeroe = false;
  }
  if (zeroe) {
    long long x = n - 2;
    cout << (x * (x + 1) / 2) << endl;
    return 0;
  }
  long long a, b, c;
  for (int i = 0; i < n; i++) {
    if (vec[i] != vec[n - 1] / 3) continue;
    for (int j = i + 1; j < n - 1; j++) {
      a = vec[i];
      b = vec[j] - a;
      c = vec[n - 1] - b - a;
      if (a == b && b == c) ways++;
    }
  }
  cout << ways;
  return 0;
}
