#include <bits/stdc++.h>
using namespace std;
int arr[100010 + 1], dp[100010 + 1];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  long long s = 0LL, f = 0LL, sol = 0LL;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    s += arr[i];
  }
  if (s % 3 != 0) {
    cout << 0 << "\n";
    return 0;
  }
  s /= 3;
  for (int i = 1; i <= n; i++) {
    f += arr[i - 1];
    if (f == s)
      dp[i] = dp[i - 1] + 1;
    else
      dp[i] = dp[i - 1];
  }
  f = 0LL;
  for (int i = n; i > 1; i--) {
    f += arr[i - 1];
    if (f == s) sol += dp[i - 2];
  }
  cout << sol << "\n";
  return 0;
}
