#include <bits/stdc++.h>
using namespace std;
int a[100009], a1[100009];
long long int ans, s = 0, t = 0;
int main() {
  int n, i, j, k, x, y;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  if (s % 3 != 0) {
    cout << 0 << " ";
    ;
    return 0;
  }
  s = s / 3;
  for (i = 1; i <= n; i++) {
    t += a[i];
    a1[i] = a1[i - 1];
    if (t == s) a1[i]++;
  }
  t = 0;
  for (i = n; i > 2; i--) {
    t += a[i];
    if (t == s) {
      ans += a1[i - 2];
    }
  }
  cout << ans << " ";
  ;
}
