#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 9;
long long a[maxN], n;
long long dpsum[maxN], dpR[maxN];
long long total;
bool sum(long long i, long long j) {
  if ((dpsum[j] - dpsum[i]) * 3 == total) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    total += a[i];
  }
  if (total % 3 != 0) {
    cout << 0;
    return 0;
  }
  dpsum[0] = 0;
  for (long long i = 1; i <= n; i++) {
    dpsum[i] = dpsum[i - 1] + a[i - 1];
  }
  for (long long i = n - 1; i > 1; i--) {
    dpR[i] = dpR[i + 1] + (sum(i, n));
  }
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    long long j = i + 1;
    if (dpsum[i] == total / 3) {
      ans += dpR[j];
    }
  }
  cout << ans << endl;
}
