#include <bits/stdc++.h>
using namespace std;
const long long INF = 1ll * 1e13;
const long long st = (1ll << 31);
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  long long ans = 0;
  cin >> n;
  vector<int> p1(n + 2, 0), p2(n + 2, 0);
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    p1[i] = p1[i - 1] + x;
  }
  for (int i = n; i > 0; i--) p2[i] = p1[n] - p1[i - 1];
  int s = p1[n];
  if (s % 3 == 0) {
    for (int i = 1; i <= n; i++) {
      p1[i] = (p1[i] == s / 3);
      p2[i] = (p2[i] == s / 3);
    }
    long long cur = 0;
    for (int i = 1; i <= n; i++) {
      if (p2[i]) ans += cur;
      cur += p1[i - 1];
    }
  }
  cout << ans << endl;
  return 0;
}
