#include <bits/stdc++.h>
using namespace std;
int n;
long long int a[100005];
long long int s[100005];
int l[100005];
int r[100005];
long long int sum;
int main() {
  cin >> n;
  s[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
    sum += a[i];
  }
  if (sum % 3 != 0 || n <= 2) {
    cout << "0" << endl;
    return 0;
  }
  int cnt = 0;
  int cot = 0;
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  for (int i = n; i >= 1; i--) {
    if (s[n] - s[i - 1] == sum / 3) {
      r[i] = r[i + 1] + 1;
    } else {
      r[i] = r[i + 1];
    }
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == sum / 3) {
      int x = r[i + 2];
      ans += x;
    }
  }
  cout << ans << endl;
  return 0;
}
