#include <bits/stdc++.h>
using namespace std;
int n, a[100001] = {}, s = 0, b[100001] = {}, c[100001] = {}, kb = 0, kc = 0;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  if (s % 3 != 0)
    cout << 0 << endl;
  else {
    long long h = s / 3, sum = 0;
    for (int i = 1; i < n - 1; i++) {
      sum += a[i];
      if (sum == h) b[++kb] = i;
    }
    sum = 0;
    for (int i = n; i > 1; i--) {
      sum += a[i];
      if (sum == h) c[++kc] = i;
    }
    long long tt = kc, as = 0;
    for (int i = 1; i <= kb; i++) {
      while (b[i] - c[tt] >= -1 && tt != 0) tt--;
      as += tt;
    }
    cout << as << endl;
  }
}
