#include <bits/stdc++.h>
const double pi = acos(-1.0);
const double eps = 1e-9;
const int inf = 2 * 1e9;
const int base = 2011;
const int raz = (int)1e6 + 1;
const double deg = pi / 180;
const int mod = 1e9 + 7;
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  if (sum % 3 != 0) {
    printf("0");
    return 0;
  }
  vector<long long> pr, sf;
  int second = 0;
  for (int i = 0; i < n; i++) {
    second += a[i];
    if (second == sum / 3) pr.push_back(i);
  }
  second = 0;
  for (int i = n - 1; i >= 0; i--) {
    second += a[i];
    if (second == sum / 3) sf.push_back(i);
  }
  if (pr.empty() or sf.empty()) {
    printf("0");
    return 0;
  }
  long long ans = 0;
  int i = 0, j = sf.size() - 1;
  do {
    while (j >= 0 and pr[i] >= sf[j] - 1) j--;
    if (j >= 0) ans += j + 1;
    i++;
  } while (i < pr.size() and j >= 0);
  printf("%lld", ans);
  return 0;
}
