#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
long long n, res, a[N], sum[N], cnt[N];
void Input() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
}
void Solve() {
  if (sum[n] % 3 != 0 || n < 3)
    cout << 0 << '\n';
  else {
    for (int i = 1; i <= n; i++) {
      if (sum[i] == (sum[n] / 3))
        cnt[i] = cnt[i - 1] + 1;
      else
        cnt[i] = cnt[i - 1];
    }
    long long curr_sum = 0;
    for (int i = n; i >= 1; i--) {
      curr_sum += a[i];
      if (curr_sum == (sum[n] / 3)) res += cnt[i - 2];
    }
    cout << res << '\n';
  }
}
int main() {
  Input();
  Solve();
  return 0;
}
