#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 100;
long long n, a[maxn], sum;
map<long long, long long> cnt;
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i], sum += a[i];
  if (sum % 3 != 0 or n <= 2) {
    cout << 0;
    return 0;
  }
  for (long long i = n, tmp = 0; i >= 3; i--) tmp += a[i], cnt[tmp]++;
  long long ans = 0, pre = 0;
  for (long long i = 1; i <= n - 2; i++) {
    pre += a[i];
    if (pre == sum / 3) ans += cnt[pre];
    cnt[sum - pre - a[i + 1]]--;
  }
  cout << ans;
}
